UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

33 lines 804 B
import { MemoryBufferNode } from './MemoryBufferNode'; /** * @category Flow shape */ export class ThrottleNode extends MemoryBufferNode { constructor(options) { super(options); this._pushReady = true; this.on('push', this.onThrottlePush.bind(this)); } onThrottlePush() { return this._handlePush(); } _handlePush() { return new Promise((resolve, reject) => { if (this._pushReady) { this._pushReady = false; this.onPull().then(() => { // Ready this._pushReady = true; return this.service.count(); }).then(count => { if (count > 0) { setTimeout(this._handlePush.bind(this), 10); } resolve(); }).catch(reject); } else { resolve(); } }); } }