@beenotung/tslib
Version:
utils library in Typescript
26 lines • 825 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntervalPool = void 0;
const tslib_1 = require("tslib");
class IntervalPool {
constructor(interval) {
this.interval = interval;
this.currentTask = Promise.resolve();
}
queue(f) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (this.currentTask = this.currentTask.then(() => new Promise((resolve, reject) => {
setTimeout(() => {
try {
resolve(f());
}
catch (e) {
reject(e);
}
}, this.interval);
})));
});
}
}
exports.IntervalPool = IntervalPool;
//# sourceMappingURL=interval-pool.js.map