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I,OAAO,CAAC,CAAC;AACpD,CAAC","file":"combinelatest.js","sourcesContent":["import { AsyncIterableX } from './asynciterablex';\nimport { identity } from '../util/identity';\nimport { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\nimport { safeRace } from '../util/safeRace';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nconst NEVER_PROMISE = new Promise(() => {});\n\ntype MergeResult<T> = { value: T; index: number };\n\nfunction wrapPromiseWithIndex<T>(promise: Promise<T>, index: number) {\n return promise.then((value) => ({ value, index })) as Promise<MergeResult<T>>;\n}\n\nexport class CombineLatestAsyncIterable<TSource> extends AsyncIterableX<TSource[]> {\n private _sources: AsyncIterable<TSource>[];\n\n constructor(sources: AsyncIterable<TSource>[]) {\n super();\n this._sources = sources;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n\n const length = this._sources.length;\n const iterators = new Array<AsyncIterator<TSource>>(length);\n const nexts = new Array<Promise<MergeResult<IteratorResult<TSource>>>>(length);\n let hasValueAll = false;\n const values = new Array<TSource>(length);\n const hasValues = new Array<boolean>(length);\n let active = length;\n\n hasValues.fill(false);\n\n for (let i = 0; i < length; i++) {\n const iterator = wrapWithAbort(this._sources[i], signal)[Symbol.asyncIterator]();\n iterators[i] = iterator;\n nexts[i] = wrapPromiseWithIndex(iterator.next(), i);\n }\n\n while (active > 0) {\n const next = safeRace(nexts);\n const {\n value: { value: value$, done: done$ },\n index,\n } = await next;\n if (done$) {\n nexts[index] = <Promise<MergeResult<IteratorResult<TSource>>>>NEVER_PROMISE;\n active--;\n } else {\n values[index] = value$;\n hasValues[index] = true;\n\n const iterator$ = iterators[index];\n nexts[index] = wrapPromiseWithIndex(iterator$.next(), index);\n\n if (hasValueAll || (hasValueAll = hasValues.every(identity))) {\n yield values;\n }\n }\n }\n }\n}\n\n/**\n * Merges multiple async-iterable sequences into one async-iterable sequence as an array whenever\n * one of the async-iterable sequences produces an element.\n *\n * @export\n * @template T The type of the elements in the first source sequence.\n * @template T2 The type of the elements in the second source sequence.\n * @param {AsyncIterable<T>} source First async-iterable source.\n * @param {AsyncIterable<T2>} source2 Second async-iterable source.\n * @returns {AsyncIterableX<[T, T2]>} An async-iterable sequence containing an array of all sources.\n */\nexport function combineLatest<T, T2>(\n source: AsyncIterable<T>,\n source2: AsyncIterable<T2>\n): AsyncIterableX<[T, T2]>;\n/**\n * Merges multiple async-iterable sequences into one async-iterable sequence as an array whenever\n * one of the async-iterable sequences produces an element.\n *\n * @export\n * @template T The type of the elements in the first source sequence.\n * @template T2 The type of the elements in the second source sequence.\n * @template T3 The type of the elements in the third source sequence.\n * @param {AsyncIterable<T>} source First async-iterable source.\n * @param {AsyncIterable<T2>} source2 Second async-iterable source.\n * @param {AsyncIterable<T3>} source3 Third async-iterable source.\n * @returns {AsyncIterableX<[T, T2, T3]>} An async-iterable sequence containing an array of all sources.\n */\nexport function combineLatest<T, T2, T3>(\n source: AsyncIterable<T>,\n source2: AsyncIterable<T2>,\n source3: AsyncIterable<T3>\n): AsyncIterableX<[T, T2, T3]>;\n/**\n * Merges multiple async-iterable sequences into one async-iterable sequence as an array whenever\n * one of the async-iterable sequences produces an element.\n *\n * @export\n * @template T The type of the elements in the first source sequence.\n * @template T2 The type of the elements in the second source sequence.\n * @template T3 The type of the elements in the third source sequence.\n * @template T4 The type of the elements in the fourth source sequence.\n * @param {AsyncIterable<T>} source First async-iterable source.\n * @param {AsyncIterable<T2>} source2 Second async-iterable source.\n * @param {AsyncIterable<T3>} source3 Third async-iterable source.\n * @param {AsyncIterable<T4>} source4 Fourth async-iterable source.\n * @returns {AsyncIterableX<[T, T2, T3, T4]>} An async-iterable sequence containing an array of all sources.\n */\nexport function combineLatest<T, T2, T3, T4>(\n source: AsyncIterable<T>,\n source2: AsyncIterable<T2>,\n source3: AsyncIterable<T3>,\n source4: AsyncIterable<T4>\n): AsyncIterableX<[T, T2, T3, T4]>;\n/**\n * Merges multiple async-iterable sequences into one async-iterable sequence as an array whenever\n * one of the async-iterable sequences produces an element.\n *\n * @export\n * @template T The type of the elements in the first source sequence.\n * @template T2 The type of the elements in the second source sequence.\n * @template T3 The type of the elements in the third source sequence.\n * @template T4 The type of the elements in the fourth source sequence.\n * @template T5 The type of the elements in the fifth source sequence.\n * @param {AsyncIterable<T>} source First async-iterable source.\n * @param {AsyncIterable<T2>} source2 Second async-iterable source.\n * @param {AsyncIterable<T3>} source3 Third async-iterable source.\n * @param {AsyncIterable<T4>} source4 Fourth async-iterable source.\n * @param {AsyncIterable<T5>} source5 Fifth async-iterable source.\n * @returns {AsyncIterableX<[T, T2, T3, T4, T5]>} An async-iterable sequence containing an array of all sources.\n */\nexport function combineLatest<T, T2, T3, T4, T5>(\n source: AsyncIterable<T>,\n source2: AsyncIterable<T2>,\n source3: AsyncIterable<T3>,\n source4: AsyncIterable<T4>,\n source5: AsyncIterable<T5>\n): AsyncIterableX<[T, T2, T3, T4, T5]>;\n/**\n * Merges multiple async-iterable sequences into one async-iterable sequence as an array whenever\n * one of the async-iterable sequences produces an element.\n *\n * @export\n * @template T The type of the elements in the first source sequence.\n * @template T2 The type of the elements in the second source sequence.\n * @template T3 The type of the elements in the third source sequence.\n * @template T4 The type of the elements in the fourth source sequence.\n * @template T5 The type of the elements in the fifth source sequence.\n * @template T6 The type of the elements in the sixth source sequence.\n * @param {AsyncIterable<T>} source First async-iterable source.\n * @param {AsyncIterable<T2>} source2 Second async-iterable source.\n * @param {AsyncIterable<T3>} source3 Third async-iterable source.\n * @param {AsyncIterable<T4>} source4 Fourth async-iterable source.\n * @param {AsyncIterable<T5>} source5 Fifth async-iterable source.\n * @param {AsyncIterable<T6>} source6 Sixth async-iterable source.\n * @returns {AsyncIterableX<[T, T2, T3, T4, T5, T6]>} An async-iterable sequence containing an array of all sources.\n */\nexport function combineLatest<T, T2, T3, T4, T5, T6>(\n source: AsyncIterable<T>,\n source2: AsyncIterable<T2>,\n source3: AsyncIterable<T3>,\n source4: AsyncIterable<T4>,\n source5: AsyncIterable<T5>,\n source6: AsyncIterable<T6>\n): AsyncIterableX<[T, T2, T3, T4, T5, T6]>;\n\n/**\n * Merges multiple async-iterable sequences into one async-iterable sequence as an array whenever\n * one of the async-iterable sequences produces an element.\n *\n * @export\n * @template T The of the elements in the source sequences.\n * @param {...AsyncIterable<T>[]} sources The async-iterable sources.\n * @returns {AsyncIterableX<T[]>} An async-iterable sequence containing an array of all sources.\n */\nexport function combineLatest<T>(...sources: AsyncIterable<T>[]): AsyncIterableX<T[]>;\nexport function combineLatest<T>(...sources: any[]): AsyncIterableX<T[]> {\n return new CombineLatestAsyncIterable<T>(sources);\n}\n"]}
\No newline at end of file