Skip to content

Instantly share code, notes, and snippets.

@pH200
Last active December 23, 2015 23:49
Show Gist options
  • Save pH200/6713146 to your computer and use it in GitHub Desktop.
Save pH200/6713146 to your computer and use it in GitHub Desktop.
q parallel example
var Q = require( 'q' );
var xyz = { x : 5, y : 6, z : 7 };
Q.all([
// simulates a time consuming io operation
Q.delay( 200 ).then( function (){
console.log( 'first task ---------------' );
console.log( 'x : ' + xyz.x );
console.log( 'y : ' + xyz.y );
console.log( 'z : ' + xyz.z + '\n' );
return [ 11, 12 ];
}),
Q.delay( 100 ).then( function (){
console.log( 'second task ---------------' );
console.log( 'x : ' + xyz.x );
console.log( 'y : ' + xyz.y );
console.log( 'z : ' + xyz.z + '\n' );
return 1000;
})
]).done( function ( from_parallel ) {
setTimeout( function (){
console.log( 'all finished callback ---------------' );
console.log( 'from_parallel : ' + JSON.stringify( from_parallel ));
console.log( 'x : ' + xyz.x );
console.log( 'y : ' + xyz.y );
console.log( 'z : ' + xyz.z + '\n' );
}, 150 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment