UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

32 lines (30 loc) 945 B
import { AsyncIterableX } from '../asynciterablex'; import { wrapWithAbort } from './withabort'; import { throwIfAborted } from '../../aborterror'; export class ReverseAsyncIterable extends AsyncIterableX { constructor(source) { super(); this._source = source; } async *[Symbol.asyncIterator](signal) { throwIfAborted(signal); const results = []; for await (const item of wrapWithAbort(this._source, signal)) { results.unshift(item); } yield* results; } } /** * Reverses the async-iterable instance. * * @export * @template TSource The type of the elements in the source sequence. * @returns {MonoTypeOperatorAsyncFunction<TSource>} The async-iterable in reversed sequence. */ export function reverse() { return function reverseOperatorFunction(source) { return new ReverseAsyncIterable(source); }; } //# sourceMappingURL=reverse.mjs.map