UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

65 lines (63 loc) 2.93 kB
import { __asyncGenerator, __await, __extends, __generator } from "tslib"; import { AsyncIterableX } from '../asynciterablex.js'; import { wrapWithAbort } from './withabort.js'; import { throwIfAborted } from '../../aborterror.js'; import { safeRace } from '../../util/safeRace.js'; var DONE_PROMISE_VALUE = undefined; /** @ignore */ var TakeUntilAsyncIterable = /** @class */ (function (_super) { __extends(TakeUntilAsyncIterable, _super); function TakeUntilAsyncIterable(source, other) { var _this = _super.call(this) || this; _this._source = source; _this._other = other; return _this; } TakeUntilAsyncIterable.prototype[Symbol.asyncIterator] = function (signal) { return __asyncGenerator(this, arguments, function _a() { var donePromise, itemsAsyncIterator, itemPromise, result; return __generator(this, function (_b) { switch (_b.label) { case 0: throwIfAborted(signal); donePromise = this._other(signal).then(function () { return DONE_PROMISE_VALUE; }); itemsAsyncIterator = wrapWithAbort(this._source, signal)[Symbol.asyncIterator](); _b.label = 1; case 1: itemPromise = itemsAsyncIterator.next(); return [4 /*yield*/, __await(safeRace([donePromise, itemPromise]))]; case 2: result = _b.sent(); if (result === DONE_PROMISE_VALUE || result.done) { return [3 /*break*/, 6]; } return [4 /*yield*/, __await(result.value)]; case 3: return [4 /*yield*/, _b.sent()]; case 4: _b.sent(); _b.label = 5; case 5: return [3 /*break*/, 1]; case 6: return [2 /*return*/]; } }); }); }; return TakeUntilAsyncIterable; }(AsyncIterableX)); export { TakeUntilAsyncIterable }; /** * Returns the elements from the source async-iterable sequence until the other function * that returns a promise produces an element. * * @template TSource The type of the elements in the source sequence. * @param {(signal?: AbortSignal) => Promise<any>} other A function that terminates the propagation of * elements in the source sequence. * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence containing the elements of the * source sequence up to the point the other function which returns a promise interrupted further propagation. */ export function takeUntil(other) { return function takeUntilOperatorFunction(source) { return new TakeUntilAsyncIterable(source, other); }; } //# sourceMappingURL=takeuntil.js.map