import { toObserver } from '../util/toobserver' ; import { observable as symbolObservable } from '../observer' ; import { Observable , PartialObserver } from '../observer' ; import { Subscription } from '../subscription' ; class BooleanSubscription implements Subscription { public isUnsubscribed = false ; unsubscribe ( ) { this . isUnsubscribed = true ; } } class AsyncIterableObservable < TSource > implements Observable < TSource > { private _source : AsyncIterable < TSource > ; constructor ( source ) { this . _source = source ; } [ symbolObservable ] ( ) { return this ; } subscribe ( next ? , error ? , complete ? ) { const observer = toObserver ( next , error , complete ) ; const subscription = new BooleanSubscription ( ) ; const it = this . _source [ Symbol . asyncIterator ] ( ) ; const f = ( ) => { it . next ( ) . then ( ( { value , done } ) => { if ( ! subscription . isUnsubscribed ) { if ( done ) { observer . complete ( ) ; } else { observer . next ( value ) ; f ( ) ; } } } ) . catch ( ( err ) => { if ( ! subscription . isUnsubscribed ) { observer . error ( err ) ; } } ) ; } ; f ( ) ; return subscription ; } } template TSource param { AsyncIterable < TSource > } source returns { Observable < TSource > } export function toObservable < TSource > ( source ) { return new AsyncIterableObservable < TSource > ( source ) ; }