1 | import { AsyncIterableX } from './asynciterablex';
|
2 | import { throwIfAborted } from '../aborterror';
|
3 | class AnonymousAsyncIterable extends AsyncIterableX {
|
4 | constructor(fn) {
|
5 | super();
|
6 | this._fn = fn;
|
7 | }
|
8 | async *[Symbol.asyncIterator](signal) {
|
9 | throwIfAborted(signal);
|
10 | const it = await this._fn(signal);
|
11 | let next;
|
12 | while (!(next = await it.next()).done) {
|
13 | yield next.value;
|
14 | }
|
15 | }
|
16 | }
|
17 | /**
|
18 | * Creates a new iterable using the specified function implementing the members of AsyncIterable
|
19 | *
|
20 | * @export
|
21 | * @template T The type of the elements returned by the enumerable sequence.
|
22 | * @param {((signal?: AbortSignal) => AsyncIterator<T> | Promise<AsyncIterator<T>>)} fn The function that creates the [Symbol.asyncIterator]() method
|
23 | * @returns {AsyncIterableX<T>} A new async-iterable instance.
|
24 | */
|
25 | export function create(fn) {
|
26 | return new AnonymousAsyncIterable(fn);
|
27 | }
|
28 |
|
29 | //# sourceMappingURL=create.mjs.map
|