ix
Version:
The Interactive Extensions for JavaScript
32 lines (30 loc) • 1.15 kB
JavaScript
import { __asyncGenerator, __await } from "tslib";
import { AsyncIterableX } from './asynciterablex.mjs';
import { throwIfAborted } from '../aborterror.mjs';
class AnonymousAsyncIterable extends AsyncIterableX {
constructor(fn) {
super();
this._fn = fn;
}
[Symbol.asyncIterator](signal) {
return __asyncGenerator(this, arguments, function* _a() {
throwIfAborted(signal);
const it = yield __await(this._fn(signal));
let next;
while (!(next = yield __await(it.next())).done) {
yield yield __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.
*/
export function create(fn) {
return new AnonymousAsyncIterable(fn);
}
//# sourceMappingURL=create.mjs.map