import { AsyncIterableX } from '../asynciterablex' ; import { MonoTypeOperatorAsyncFunction } from '../../interfaces' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export class ExpandAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _source : AsyncIterable < TSource > ; private _selector : ( value : TSource , signal ? : AbortSignal ) => AsyncIterable < TSource > | Promise < AsyncIterable < TSource > > ; constructor ( source , selector ) { super ( ) ; this . _source = source ; this . _selector = selector ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; const q = [ this . _source ] ; while ( q . length > 0 ) { const src = q . shift ( ) ; for await ( const item of wrapWithAbort ( src ! , signal ) ) { const items = await this . _selector ( item , signal ) ; q . push ( items ) ; yield item ; } } } } template TSource param { ( ( value : TSource , signal ? : AbortSignal * ) => AsyncIterable < TSource > | Promise < AsyncIterable < TSource > > ) } selector returns { MonoTypeOperatorAsyncFunction < TSource > } export function expand < TSource > ( selector ) { return function expandOperatorFunction ( source ) : AsyncIterableX < TSource > { return new ExpandAsyncIterable < TSource > ( source , selector ) ; } ; }