UNPKG

@iotile/iotile-device

Version:

A typescript library for interfacing with IOTile BLE devices

34 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class SlidingWindowReorderer { constructor(callback) { this.callback = callback; this.onHold = {}; this.nextExpected = 0; } call(value, sequence) { if (sequence == null) { this.callback(value); return; } if (sequence != this.nextExpected) console.warn(`Received out of order: expected ${this.nextExpected} got ${sequence}`); this.onHold[sequence] = value; this.tryDispatchInOrder(); } tryDispatchInOrder() { while (this.nextExpected in this.onHold) { try { let value = this.onHold[this.nextExpected]; delete this.onHold[this.nextExpected]; this.nextExpected += 1; this.callback(value); } catch (err) { console.error("Error in callback in SlidingWindowReorderer", err); } } } } exports.SlidingWindowReorderer = SlidingWindowReorderer; //# sourceMappingURL=sliding-window.js.map