license Zone . __load_patch ( 'bluebird' , ( global , Zone , api ) => { const BLUEBIRD = 'bluebird' ; ( Zone as any ) [ Zone . __symbol__ ( BLUEBIRD ) ] = function patchBluebird ( Bluebird ) { const bluebirdApis = [ 'then' , 'spread' , 'finally' ] ; bluebirdApis . forEach ( bapi => { api . patchMethod ( Bluebird . prototype , bapi , ( delegate ) => ( self , args ) => { const zone = Zone . current ; for ( let i = 0 ; i < args . length ; i ++ ) { const func = args [ i ] ; if ( typeof func === 'function' ) { args [ i ] = function ( ) { const argSelf = this ; const argArgs = arguments ; return new Bluebird ( ( res , rej ) => { zone . scheduleMicroTask ( 'Promise.then' , ( ) => { try { res ( func . apply ( argSelf , argArgs ) ) ; } catch ( error ) { rej ( error ) ; } } ) ; } ) ; } ; } } return delegate . apply ( self , args ) ; } ) ; } ) ; Bluebird . onPossiblyUnhandledRejection ( function ( e , promise ) { try { Zone . current . runGuarded ( ( ) => { throw e ; } ) ; } catch ( err ) { api . onUnhandledError ( err ) ; } } ) ; global [ api . symbol ( 'ZoneAwarePromise' ) ] = Bluebird ; } ; } ) ;