import { AsyncIterableX } from './asynciterablex' ; import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; class DeferAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _fn : ( signal ? : AbortSignal ) => AsyncIterable < TSource > | Promise < AsyncIterable < TSource > > ; constructor ( fn ) { super ( ) ; this . _fn = fn ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; const items = await this . _fn ( signal ) ; for await ( const item of wrapWithAbort ( items , signal ) ) { yield item ; } } } template TSource param { ( ( signal ? : AbortSignal ) => AsyncIterable < TSource > | Promise < AsyncIterable < TSource > > ) } factory returns { AsyncIterableX < TSource > } export function defer < TSource > ( factory ) { return new DeferAsyncIterable < TSource > ( factory ) ; }