import { AsyncIterableX } from '../asynciterablex' ; import { MonoTypeOperatorAsyncFunction } from '../../interfaces' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export class TakeAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _source : AsyncIterable < TSource > ; private _count : number ; constructor ( source , count ) { super ( ) ; this . _source = source ; this . _count = count ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; let i = this . _count ; if ( i > 0 ) { for await ( const item of wrapWithAbort ( this . _source , signal ) ) { yield item ; if ( -- i === 0 ) { break ; } } } } } template TSource param { number } count returns { MonoTypeOperatorAsyncFunction < TSource > } export function take < TSource > ( count ) { return function takeOperatorFunction ( source ) : AsyncIterableX < TSource > { return new TakeAsyncIterable < TSource > ( source , count ) ; } ; }