ix
Version:
The Interactive Extensions for JavaScript
55 lines (53 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.delayEach = exports.DelayEachAsyncIterable = void 0;
const tslib_1 = require("tslib");
const asynciterablex_js_1 = require("../asynciterablex.js");
const _sleep_js_1 = require("../_sleep.js");
const withabort_js_1 = require("./withabort.js");
const aborterror_js_1 = require("../../aborterror.js");
/** @ignore */
class DelayEachAsyncIterable extends asynciterablex_js_1.AsyncIterableX {
constructor(source, dueTime) {
super();
this._source = source;
this._dueTime = dueTime;
}
[Symbol.asyncIterator](signal) {
return tslib_1.__asyncGenerator(this, arguments, function* _a() {
var _b, e_1, _c, _d;
(0, aborterror_js_1.throwIfAborted)(signal);
try {
for (var _e = true, _f = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._source, signal)), _g; _g = yield tslib_1.__await(_f.next()), _b = _g.done, !_b; _e = true) {
_d = _g.value;
_e = false;
const item = _d;
yield tslib_1.__await((0, _sleep_js_1.sleep)(this._dueTime, signal));
yield yield tslib_1.__await(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_e && !_b && (_c = _f.return)) yield tslib_1.__await(_c.call(_f));
}
finally { if (e_1) throw e_1.error; }
}
});
}
}
exports.DelayEachAsyncIterable = DelayEachAsyncIterable;
/**
* Delays the emitting of each items in the async-iterable by the given due time.
*
* @template TSource The type of elements in the source sequence.
* @param {number} dueTime The delay duration in milliseconds
* @returns {MonoTypeOperatorAsyncFunction<TSource>} An operator which takes an async-iterable and delays each item in the sequence by the given time.
*/
function delayEach(dueTime) {
return function delayEachOperatorFunction(source) {
return new DelayEachAsyncIterable(source, dueTime);
};
}
exports.delayEach = delayEach;
//# sourceMappingURL=delayeach.js.map