UNPKG

datainout

Version:

Import and reports data

59 lines (57 loc) 1.33 kB
var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/common/core/QueueData.ts var QueueData = class { constructor(size = 50) { this.cells = []; this.resolveFunc = () => { }; this.size = size; this.waitingFunc = this.createWaiter(); } createWaiter() { return new Promise((resolve) => { this.resolveFunc = resolve; }); } waiting() { return __async(this, null, function* () { if (this.cells.length < this.size) return; yield this.waitingFunc; }); } shift() { const data = this.cells.shift(); if (this.cells.length === this.size - 1) { this.resolveFunc(); } return data; } add(data) { this.cells.push(data); if (this.cells.length === this.size) { this.waitingFunc = this.createWaiter(); } } }; export { QueueData };