UNPKG

901 BJavaScriptView Raw
1import { IterableX } from './iterablex';
2class DeferIterable extends IterableX {
3 constructor(fn) {
4 super();
5 this._fn = fn;
6 }
7 *[Symbol.iterator]() {
8 for (const item of this._fn()) {
9 yield item;
10 }
11 }
12}
13/**
14 * Returns an iterable sequence that invokes the specified factory function whenever a call to [Symbol.iterator] has been made.
15 *
16 * @export
17 * @template TSource The type of the elements in the sequence returned by the factory function, and in the resulting sequence.
18 * @param {(() => Iterable<TSource>)} factory iterable factory function to invoke for each call to [Symbol.iterator].
19 * @returns {AsyncIterableX<TSource>} An iterable sequence whose observers trigger an invocation of the given iterable factory function.
20 */
21export function defer(factory) {
22 return new DeferIterable(factory);
23}
24
25//# sourceMappingURL=defer.mjs.map