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C;IAC5D,CAAC,CAAC;AACJ,CAAC","file":"takeuntil.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nconst DONE_PROMISE_VALUE = undefined;\n\nexport class TakeUntilAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n  private _source: AsyncIterable<TSource>;\n  private _other: (signal?: AbortSignal) => Promise<any>;\n\n  constructor(source: AsyncIterable<TSource>, other: (signal?: AbortSignal) => Promise<any>) {\n    super();\n    this._source = source;\n    this._other = other;\n  }\n\n  async *[Symbol.asyncIterator](signal?: AbortSignal) {\n    throwIfAborted(signal);\n    const donePromise = this._other(signal).then(() => DONE_PROMISE_VALUE);\n    const itemsAsyncIterator = wrapWithAbort(this._source, signal)[Symbol.asyncIterator]();\n    for (;;) {\n      const itemPromise = itemsAsyncIterator.next();\n      const result = await Promise.race([donePromise, itemPromise]);\n      if (result === DONE_PROMISE_VALUE || result.done) {\n        break;\n      }\n      yield result.value;\n    }\n  }\n}\n\n/**\n * Returns the elements from the source async-iterable sequence until the other function\n * that returns a promise produces an element.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {(signal?: AbortSignal) => Promise<any>} other A function that terminates the propagation of\n * elements in the source sequence.\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence containing the elements of the\n * source sequence up to the point the other function which returns a promise interrupted further propagation.\n */\nexport function takeUntil<TSource>(\n  other: (signal?: AbortSignal) => Promise<any>\n): MonoTypeOperatorAsyncFunction<TSource> {\n  return function takeUntilOperatorFunction(\n    source: AsyncIterable<TSource>\n  ): AsyncIterableX<TSource> {\n    return new TakeUntilAsyncIterable<TSource>(source, other);\n  };\n}\n"]}