import { Subject } from 'rxjs' ; export class EventEmitter < T > extends Subject < T > { private _isAsync : boolean ; constructor ( isAsync = true ) { super ( ) ; this . _isAsync = isAsync ; } emit ( value ) { super . next ( value ) ; } deprecated next ( value ) { super . next ( value ) ; } subscribe ( generatorOrNext ? , error ? , complete ? ) { let schedulerFn ; let errorFn = ( err ) => null ; let completeFn = ( ) => null ; if ( generatorOrNext && typeof generatorOrNext === 'object' ) { schedulerFn = this . _isAsync ? value => { setTimeout ( ( ) => generatorOrNext . next ( value ) ) ; } : value => { generatorOrNext . next ( value ) ; } ; if ( generatorOrNext . error ) { errorFn = this . _isAsync ? err => { setTimeout ( ( ) => generatorOrNext . error ( err ) ) ; } : err => { generatorOrNext . error ( err ) ; } ; } if ( generatorOrNext . complete ) { completeFn = this . _isAsync ? ( ) => { setTimeout ( ( ) => generatorOrNext . complete ( ) ) ; } : ( ) => { generatorOrNext . complete ( ) ; } ; } } else { schedulerFn = this . _isAsync ? value => { setTimeout ( ( ) => generatorOrNext ( value ) ) ; } : value => { generatorOrNext ( value ) ; } ; if ( error ) { errorFn = this . _isAsync ? err => { setTimeout ( ( ) => error ( err ) ) ; } : err => { error ( err ) ; } ; } if ( complete ) { completeFn = this . _isAsync ? ( ) => { setTimeout ( ( ) => complete ( ) ) ; } : ( ) => { complete ( ) ; } ; } } return super . subscribe ( schedulerFn , errorFn , completeFn ) ; } }