ix
Version:
The Interactive Extensions for JavaScript
36 lines (34 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = void 0;
const tslib_1 = require("tslib");
const asynciterablex_js_1 = require("./asynciterablex.js");
const aborterror_js_1 = require("../aborterror.js");
class AnonymousAsyncIterable extends asynciterablex_js_1.AsyncIterableX {
constructor(fn) {
super();
this._fn = fn;
}
[Symbol.asyncIterator](signal) {
return tslib_1.__asyncGenerator(this, arguments, function* _a() {
(0, aborterror_js_1.throwIfAborted)(signal);
const it = yield tslib_1.__await(this._fn(signal));
let next;
while (!(next = yield tslib_1.__await(it.next())).done) {
yield yield tslib_1.__await(next.value);
}
});
}
}
/**
* Creates a new iterable using the specified function implementing the members of AsyncIterable
*
* @template T The type of the elements returned by the enumerable sequence.
* @param {((signal?: AbortSignal) => AsyncIterator<T> | Promise<AsyncIterator<T>>)} fn The function that creates the [Symbol.asyncIterator]() method
* @returns {AsyncIterableX<T>} A new async-iterable instance.
*/
function create(fn) {
return new AnonymousAsyncIterable(fn);
}
exports.create = create;
//# sourceMappingURL=create.js.map