import { AsyncIterableX } from '../asynciterablex' ; import { MonoTypeOperatorAsyncFunction } from '../../interfaces' ; import { sleep } from '../_sleep' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export class DelayAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _source : AsyncIterable < TSource > ; private _dueTime : number ; constructor ( source , dueTime ) { super ( ) ; this . _source = source ; this . _dueTime = dueTime ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; await sleep ( this . _dueTime , signal ) ; for await ( const item of wrapWithAbort ( this . _source , signal ) ) { yield item ; } } } template TSource param { number } dueTime returns { MonoTypeOperatorAsyncFunction < TSource > } export function delay < TSource > ( dueTime ) { return function delayOperatorFunction ( source ) : AsyncIterableX < TSource > { return new DelayAsyncIterable < TSource > ( source , dueTime ) ; } ; }