import { AsyncIterableX } from './asynciterablex' ; import { returnAsyncIterator } from '../util/returniterator' ; import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; export class CatchAllAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _source : Iterable < AsyncIterable < TSource > > ; constructor ( source ) { super ( ) ; this . _source = source ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; let error = null ; let hasError = false ; for ( const source of this . _source ) { const it = wrapWithAbort ( source , signal ) [ Symbol . asyncIterator ] ( ) ; error = null ; hasError = false ; while ( 1 ) { let c = < TSource > { } ; try { const { done , value } = await it . next ( ) ; if ( done ) { await returnAsyncIterator ( it ) ; break ; } c = value ; } catch ( e ) { error = e ; hasError = true ; await returnAsyncIterator ( it ) ; break ; } yield c ; } if ( ! hasError ) { break ; } } if ( hasError ) { throw error ; } } } template T param { Iterable < AsyncIterable < T > > } source returns { AsyncIterableX < T > } export function catchAll < T > ( source ) { return new CatchAllAsyncIterable < T > ( source ) ; } template T param { ... AsyncIterable < T > [ ] } args returns { AsyncIterableX < T > } export function catchError < T > ( ... args ) { return new CatchAllAsyncIterable < T > ( args ) ; }