ix
Version:
The Interactive Extensions for JavaScript
48 lines (46 loc) • 1.72 kB
JavaScript
import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
import { AsyncIterableX } from '../asynciterablex.mjs';
import { wrapWithAbort } from './withabort.mjs';
import { throwIfAborted } from '../../aborterror.mjs';
/** @ignore */
export class ReverseAsyncIterable extends AsyncIterableX {
constructor(source) {
super();
this._source = source;
}
[Symbol.asyncIterator](signal) {
return __asyncGenerator(this, arguments, function* _a() {
var _b, e_1, _c, _d;
throwIfAborted(signal);
const results = [];
try {
for (var _e = true, _f = __asyncValues(wrapWithAbort(this._source, signal)), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
_d = _g.value;
_e = false;
const item = _d;
results.unshift(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
}
finally { if (e_1) throw e_1.error; }
}
yield __await(yield* __asyncDelegator(__asyncValues(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.mjs.map