import { AsyncIterableX } from './asynciterablex.js'; import { wrapWithAbort } from './operators/withabort.js'; import { throwIfAborted } from '../aborterror.js'; /** @ignore */ export class ConcatAsyncIterable extends AsyncIterableX { private _source: Iterable>; constructor(source: Iterable>) { super(); this._source = source; } async *[Symbol.asyncIterator](signal?: AbortSignal) { throwIfAborted(signal); for (const outer of this._source) { for await (const item of wrapWithAbort(outer, signal)) { yield item; } } } } export function _concatAll( source: Iterable> ): AsyncIterableX { return new ConcatAsyncIterable(source); } /** * Concatenates the second async-iterable sequence to the first async-iterable sequence upon successful termination of the first. * * @template T The type of the elements in the first source sequence. * @template T2 The type of the elements in the second source sequence. * @param {AsyncIterable} v1 First async-iterable source. * @param {AsyncIterable} v2 Second async-iterable source. * @returns {(AsyncIterableX)} An async-iterable sequence that contains the elements of the first sequence, * followed by those of the second the sequence. */ export function concat(v1: AsyncIterable, v2: AsyncIterable): AsyncIterableX; /** * Concatenates all async-iterable sequences in the given sequences, as long as the previous async-iterable * sequence terminated successfully. * * @template T The type of the elements in the first source sequence. * @template T2 The type of the elements in the second source sequence. * @template T3 The type of the elements in the third source sequence. * @param {AsyncIterable} v1 First async-iterable source. * @param {AsyncIterable} v2 Second async-iterable source. * @param {AsyncIterable} v3 Third async-iterable source. * @returns {(AsyncIterableX)} An async-iterable sequence that contains the elements of each given sequence, in sequential order. */ export function concat( v1: AsyncIterable, v2: AsyncIterable, v3: AsyncIterable ): AsyncIterableX; /** * Concatenates all async-iterable sequences in the given sequences, as long as the previous async-iterable * sequence terminated successfully. * * @template T The type of the elements in the first source sequence. * @template T2 The type of the elements in the second source sequence. * @template T3 The type of the elements in the third source sequence. * @template T4 The type of the elements in the fourth source sequence. * @param {AsyncIterable} v1 First async-iterable source. * @param {AsyncIterable} v2 Second async-iterable source. * @param {AsyncIterable} v3 Third async-iterable source. * @param {AsyncIterable} v4 Fourth async-iterable source. * @returns {(AsyncIterableX)} An async-iterable sequence that contains the elements of each given sequence, in sequential order. */ export function concat( v1: AsyncIterable, v2: AsyncIterable, v3: AsyncIterable, v4: AsyncIterable ): AsyncIterableX; /** * Concatenates all async-iterable sequences in the given sequences, as long as the previous async-iterable * sequence terminated successfully. * * @template T The type of the elements in the first source sequence. * @template T2 The type of the elements in the second source sequence. * @template T3 The type of the elements in the third source sequence. * @template T4 The type of the elements in the fourth source sequence. * @template T5 The type of the elements in the fifth source sequence. * @param {AsyncIterable} v1 First async-iterable source. * @param {AsyncIterable} v2 Second async-iterable source. * @param {AsyncIterable} v3 Third async-iterable source. * @param {AsyncIterable} v4 Fourth async-iterable source. * @param {AsyncIterable} v5 Fifth async-iterable source. * @returns {(AsyncIterable)} An async-iterable sequence that contains the elements of each * given sequence, in sequential order. */ export function concat( v1: AsyncIterable, v2: AsyncIterable, v3: AsyncIterable, v4: AsyncIterable, v5: AsyncIterable ): AsyncIterable; /** * Concatenates all async-iterable sequences in the given sequences, as long as the previous async-iterable * sequence terminated successfully. * * @template T The type of the elements in the first source sequence. * @template T2 The type of the elements in the second source sequence. * @template T3 The type of the elements in the third source sequence. * @template T4 The type of the elements in the fourth source sequence. * @template T5 The type of the elements in the fifth source sequence. * @template T6 The type of the elements in the sixth source sequence. * @param {AsyncIterable} v1 First async-iterable source. * @param {AsyncIterable} v2 Second async-iterable source. * @param {AsyncIterable} v3 Third async-iterable source. * @param {AsyncIterable} v4 Fourth async-iterable source. * @param {AsyncIterable} v5 Fifth async-iterable source. * @param {AsyncIterable} v6 Sixth async-iterable source. * @returns {(AsyncIterable)} An async-iterable sequence that contains the elements of each * given sequence, in sequential order. */ export function concat( v1: AsyncIterable, v2: AsyncIterable, v3: AsyncIterable, v4: AsyncIterable, v5: AsyncIterable, v6: AsyncIterable ): AsyncIterable; /** * Concatenates all async-iterable sequences in the given sequences, as long as the previous async-iterable * sequence terminated successfully. * * @template T The type of the elements in the sequences. * @param {...AsyncIterable[]} args The async-iterable sources. * @returns {AsyncIterableX} An async-iterable sequence that contains the elements of each given sequence, in sequential order. */ export function concat(...args: AsyncIterable[]): AsyncIterableX { return new ConcatAsyncIterable(args); }