Created
September 21, 2015 13:38
-
-
Save yomotsu/95752343c22f43896ace to your computer and use it in GitHub Desktop.
bluebird.js コード例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = function( val ) { | |
return new Promise( function( onFulfilled, onRejected ) { | |
setTimeout( function() { onFulfilled( 1 ); }, 2000 ); | |
} ); | |
}; | |
var b = function( val ) { | |
return new Promise( function( onFulfilled, onRejected ) { | |
console.log( val ); | |
setTimeout( function() { onFulfilled( 2 ); }, 1000 ); | |
} ); | |
} | |
var c = function( val ) { | |
console.log( val ); | |
}; | |
Promise.resolve().then( a ).then( b ).then( c ); | |
//-- | |
var a1 = function( val ) { | |
return new Promise( function( onFulfilled, onRejected ) { | |
setTimeout( function() { onFulfilled( 1 ); }, 1000 ); | |
} ); | |
}; | |
var a2 = function( val ) { | |
return new Promise( function( onFulfilled, onRejected ) { | |
setTimeout( function() { onFulfilled( 2 ); }, 2000 ); | |
} ); | |
}; | |
var b = function( val ) { | |
console.log( val ); // [ 1, 2 ] | |
}; | |
Promise.all( [ a1(), a2() ] ).then( b ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment