@openhps/core
Version:
Open Hybrid Positioning System - Core component
42 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottleNode = void 0;
const MemoryBufferNode_1 = require("./MemoryBufferNode");
/**
* @category Flow shape
*/
class ThrottleNode extends MemoryBufferNode_1.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();
}
});
}
}
exports.ThrottleNode = ThrottleNode;
//# sourceMappingURL=ThrottleNode.js.map