Created
June 24, 2012 18:49
-
-
Save sandeep45/2984399 to your computer and use it in GitHub Desktop.
Me Playing with step.js
This file contains 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 step = require("step"); | |
var color = require("colors"); | |
/* | |
* A fake task which prints the message sent. | |
* It take upto 2 seconds to do the print. | |
* After printing it will call the callback. | |
*/ | |
var task = function(msg,cb){ | |
console.info(("starting task - " + msg).green); | |
setTimeout(function(){ | |
console.info(("finished task - " + msg).blue); | |
console.info(("--").red); | |
cb(); | |
},Math.ceil(Math.random()*3000)); | |
} | |
step( | |
function step1(){ | |
task(" step1",this); | |
}, | |
function step2(){ | |
task(" step2",this); | |
}, | |
function step3(){ | |
task(" step3",this); | |
}, | |
function step4(){ | |
task(" step4",this); | |
}, | |
function step5(){ | |
task(" step5",this); | |
}, | |
/* | |
* Parllel tasks all run together | |
* The next step is NOT executed | |
* till all of the parllel tasks finish | |
*/ | |
function step678(){ | |
task(" step6",this.parallel()); | |
task(" step7",this.parallel()); | |
task(" step8",this.parallel()); | |
}, | |
function step9(){ | |
task(" step9",this); | |
}, | |
function step10(){ | |
task(" step10",this); | |
}, | |
function step11(){ | |
task(" step11",this); | |
}, | |
/* | |
* Tasks of a group run immidiately | |
* they dont wait on each other | |
* Also the next step is also instantly executed | |
* The next step does not wait for the group | |
* tasks to finish | |
*/ | |
function step121314(){ | |
var group = this.group(); | |
task(" step12",group); | |
task(" step13",group); | |
task(" step14",group); | |
}, | |
function step15(){ | |
task(" step15",this); | |
}, | |
function step16(){ | |
task(" step16",this); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment