import { AsyncIterableX } from '../asynciterablex.js'; import { wrapWithAbort } from './withabort.js'; import { throwIfAborted } from '../../aborterror.js'; /** @ignore */ export class StartWithAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _args: TSource[]; constructor(source: AsyncIterable, args: TSource[]) { super(); this._source = source; this._args = args; } async *[Symbol.asyncIterator](signal?: AbortSignal) { throwIfAborted(signal); for (const x of this._args) { yield x; } for await (const item of wrapWithAbort(this._source, signal)) { yield item; } } } /** * Prepend a value to an async-iterable sequence. * * @template TSource The type of the elements in the source sequence. * @param {...TSource[]} args Elements to prepend to the specified sequence. * @returns The source sequence prepended with the specified values. */ export function startWith(...args: TSource) { return function startWithOperatorFunction( source: AsyncIterable ): AsyncIterableX { return new StartWithAsyncIterable(source, args); }; }