// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only export type MaybeAsyncIterable = Iterable | AsyncIterable; export function concat( iterables: Iterable> ): AsyncIterable { return new ConcatAsyncIterable(iterables); } class ConcatAsyncIterable implements AsyncIterable { readonly #iterables: Iterable>; constructor(iterables: Iterable>) { this.#iterables = iterables; } async *[Symbol.asyncIterator](): AsyncIterator { for (const iterable of this.#iterables) { // oxlint-disable-next-line no-await-in-loop for await (const value of iterable) { yield value; } } } } export function wrapPromise( promise: Promise> ): AsyncIterable { return new WrapPromiseAsyncIterable(promise); } // oxlint-disable-next-line max-classes-per-file class WrapPromiseAsyncIterable implements AsyncIterable { readonly #promise: Promise>; constructor(promise: Promise>) { this.#promise = promise; } async *[Symbol.asyncIterator](): AsyncIterator { for await (const value of await this.#promise) { yield value; } } }