import { Subscriber } from "rxjs" ; export class CompleteHandler < T > { private currentNumberOfAsyncCalls = 0 ; private isComplete : boolean ; private softCompleteObject : any ; public constructor ( private observer , private totalNumberOfAsyncCalls ) { } public complete ( obj ? ) { if ( this . isComplete ) { return ; } this . observer . next ( obj ) ; this . observer . complete ( ) ; this . isComplete = true ; } public softComplete ( obj ? ) { if ( this . isComplete ) { return ; } if ( ++ this . currentNumberOfAsyncCalls < this . totalNumberOfAsyncCalls ) { return ; } this . observer . next ( this . softCompleteObject ? this . softCompleteObject : obj ) ; this . observer . complete ( ) ; this . isComplete = true ; } public completeAsLast ( obj ? ) { this . softCompleteObject = obj ; this . softComplete ( ) ; } }