UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

33 lines (31 loc) 970 B
import { AsyncIterableX } from '../asynciterablex.js'; import { wrapWithAbort } from './withabort.js'; import { throwIfAborted } from '../../aborterror.js'; /** @ignore */ export class ReverseAsyncIterable extends AsyncIterableX { _source; 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. * * @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.js.map