import { AsyncIterableX } from './asynciterablex' ; import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; class WhileAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _condition : ( signal ? : AbortSignal ) => boolean | Promise < boolean > ; private _source : AsyncIterable < TSource > ; constructor ( condition , source ) { super ( ) ; this . _condition = condition ; this . _source = source ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; while ( await this . _condition ( signal ) ) { for await ( const item of wrapWithAbort ( this . _source , signal ) ) { yield item ; } } } } template TSource param { AsyncIterable < TSource > } source param { ( ( signal ? : AbortSignal ) => boolean | Promise < boolean > ) } condition returns { AsyncIterableX < TSource > } export function whileDo < TSource > ( source , condition ) { return new WhileAsyncIterable < TSource > ( condition , source ) ; }