ix
Version:
The Interactive Extensions for JavaScript
50 lines (48 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defer = void 0;
const tslib_1 = require("tslib");
const asynciterablex_js_1 = require("./asynciterablex.js");
const withabort_js_1 = require("./operators/withabort.js");
const aborterror_js_1 = require("../aborterror.js");
class DeferAsyncIterable extends asynciterablex_js_1.AsyncIterableX {
constructor(fn) {
super();
this._fn = fn;
}
[Symbol.asyncIterator](signal) {
return tslib_1.__asyncGenerator(this, arguments, function* _a() {
var _b, e_1, _c, _d;
(0, aborterror_js_1.throwIfAborted)(signal);
const items = yield tslib_1.__await(this._fn(signal));
try {
for (var _e = true, _f = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(items, signal)), _g; _g = yield tslib_1.__await(_f.next()), _b = _g.done, !_b; _e = true) {
_d = _g.value;
_e = false;
const item = _d;
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; }
}
});
}
}
/**
* Returns an async-iterable sequence that invokes the specified factory function whenever a call to [Symbol.asyncIterator] has been made.
*
* @template TSource The type of the elements in the sequence returned by the factory function, and in the resulting sequence.
* @param {((signal?: AbortSignal) => AsyncIterable<TSource> | Promise<AsyncIterable<TSource>>)} factory Async-iterable factory function to
* invoke for each call to [Symbol.asyncIterator].
* @returns {AsyncIterableX<TSource>} An async-iterable sequence whose observers trigger an invocation of the given async-iterable factory function.
*/
function defer(factory) {
return new DeferAsyncIterable(factory);
}
exports.defer = defer;
//# sourceMappingURL=defer.js.map