UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

49 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FrameDebounceNode = void 0; const ProcessingNode_1 = require("../ProcessingNode"); const utils_1 = require("../../utils"); /** * @category Flow shape */ class FrameDebounceNode extends ProcessingNode_1.ProcessingNode { constructor(timeout, timeoutUnit) { super(); this._accept = true; this._timeout = timeout; this._timeoutUnit = timeoutUnit; this.once('build', this._start.bind(this)); this.once('destroy', this._stop.bind(this)); } /** * Start the timeout timer * @returns {Promise<void>} Timer promise */ _start() { return new Promise((resolve) => { this._timer = setInterval(() => { this._accept = true; }, this._timeoutUnit.convert(this._timeout, utils_1.TimeUnit.MILLISECOND)); resolve(); this.emit('ready'); }); } _stop() { if (this._timer !== undefined) { clearInterval(this._timer); } } process(frame) { return new Promise((resolve) => { if (this._accept) { this._accept = false; resolve(frame); } else { resolve(undefined); } }); } } exports.FrameDebounceNode = FrameDebounceNode; //# sourceMappingURL=FrameDebounceNode.js.map