Skip to content

Instantly share code, notes, and snippets.

@yomotsu
Created September 21, 2015 13:38
Show Gist options
  • Save yomotsu/95752343c22f43896ace to your computer and use it in GitHub Desktop.
Save yomotsu/95752343c22f43896ace to your computer and use it in GitHub Desktop.
bluebird.js コード例
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