import { AsyncIterableX } from '../asynciterablex' ; import { PartialAsyncObserver } from '../../observer' ; import { MonoTypeOperatorAsyncFunction } from '../../interfaces' ; import { toObserver } from '../../util/toobserver' ; import { wrapWithAbort } from './withabort' ; import { AbortError , throwIfAborted } from '../../aborterror' ; export class TapAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _source : AsyncIterable < TSource > ; private _observer : PartialAsyncObserver < TSource > ; constructor ( source , observer ) { super ( ) ; this . _source = source ; this . _observer = observer ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; const source = wrapWithAbort ( this . _source , signal ) ; const it = source [ Symbol . asyncIterator ] ( ) ; while ( 1 ) { let next ; try { next = await it . next ( ) ; } catch ( e ) { if ( e instanceof AbortError ) { throw e ; } if ( this . _observer . error ) { await this . _observer . error ( e ) ; } throw e ; } if ( next . done ) { if ( this . _observer . complete ) { await this . _observer . complete ( ) ; } break ; } if ( this . _observer . next ) { await this . _observer . next ( next . value ) ; } yield next . value ; } } } template TSource param { PartialAsyncObserver < TSource > } observer returns { MonoTypeOperatorAsyncFunction < TSource > } export function tap < TSource > ( observer ) ; template TSource param { ( ( ( value : TSource ) => any ) | null ) } next param { ( ( ( err : any ) => any ) | null ) } error param { ( ( ( ) => any ) | null ) } complete returns { MonoTypeOperatorAsyncFunction < TSource > } export function tap < TSource > ( next ? , error ? , complete ? ) ; template TSource param { ( PartialAsyncObserver < TSource > | ( ( value : TSource ) => any ) | null ) } observerOrNext param { ( ( ( err : any ) => any ) | null ) } error param { ( ( ( ) => any ) | null ) } complete returns { MonoTypeOperatorAsyncFunction < TSource > } export function tap < TSource > ( observerOrNext ? , error ? , complete ? ) { return function tapOperatorFunction ( source ) : AsyncIterableX < TSource > { return new TapAsyncIterable < TSource > ( source , toObserver ( observerOrNext , error , complete ) ) ; } ; }