import { wrapWithAbort } from './operators/withabort' ; import { AsyncIterableX } from './asynciterablex' ; import { returnAsyncIterator } from '../util/returniterator' ; import { throwIfAborted } from '../aborterror' ; export class ZipAsyncIterable < TSource > extends AsyncIterableX < TSource [ ] > { private _sources : AsyncIterable < TSource > [ ] ; constructor ( sources ) { super ( ) ; this . _sources = sources ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; const sourcesLength = this . _sources . length ; const its = this . _sources . map ( ( x ) => wrapWithAbort ( x , signal ) [ Symbol . asyncIterator ] ( ) ) ; while ( sourcesLength > 0 ) { const values = new Array ( sourcesLength ) ; for ( let i = - 1 ; ++ i < sourcesLength ; ) { const { value , done } = await its [ i ] . next ( ) ; if ( done ) { await Promise . all ( its . map ( returnAsyncIterator ) ) ; return undefined ; } values [ i ] = value ; } yield values ; } } } template T template T2 param { AsyncIterable < T > } source param { AsyncIterable < T2 > } source2 returns { AsyncIterableX < [ T , T2 ] > } export function zip < T , T2 > ( source , source2 ) ; template T template T2 template T3 param { AsyncIterable < T > } source param { AsyncIterable < T2 > } source2 param { AsyncIterable < T3 > } source3 returns { AsyncIterableX < [ T , T2 , T3 ] > } export function zip < T , T2 , T3 > ( source , source2 , source3 ) ; template T template T2 template T3 template T4 param { AsyncIterable < T > } source param { AsyncIterable < T2 > } source2 param { AsyncIterable < T3 > } source3 param { AsyncIterable < T4 > } source4 returns { AsyncIterableX < [ T , T2 , T3 , T4 ] > } export function zip < T , T2 , T3 , T4 > ( source , source2 , source3 , source4 ) ; template T template T2 template T3 template T4 template T5 param { AsyncIterable < T > } source param { AsyncIterable < T2 > } source2 param { AsyncIterable < T3 > } source3 param { AsyncIterable < T4 > } source4 param { AsyncIterable < T5 > } source5 returns { AsyncIterableX < [ T , T2 , T3 , T4 , T5 ] > } export function zip < T , T2 , T3 , T4 , T5 > ( source , source2 , source3 , source4 , source5 ) ; template T template T2 template T3 template T4 template T5 template T6 param { AsyncIterable < T > } source param { AsyncIterable < T2 > } source2 param { AsyncIterable < T3 > } source3 param { AsyncIterable < T4 > } source4 param { AsyncIterable < T5 > } source5 param { AsyncIterable < T6 > } source6 returns { AsyncIterableX < [ T , T2 , T3 , T4 , T5 , T6 ] > } export function zip < T , T2 , T3 , T4 , T5 , T6 > ( source , source2 , source3 , source4 , source5 , source6 ) ; template T param { ... AsyncIterable < T > [ ] } sources returns { AsyncIterableX < T [ ] > } export function zip < T > ( ... sources ) ; export function zip < T > ( ... sources ) { return new ZipAsyncIterable < T > ( sources ) ; }