I've actually just started learning to use Async as well. Firstly, if you have a bit a time to spare, I recommend the nodeschool.io workshop "async-you". I just ran through it yesterday and it's a pretty good introduction to the module.
I was playing around with your example some, here's a version using series and timesSeries like Francesco recommends: https://gist.github.com/DanSchmidt/0f76d6eac31b538fe0df On Wednesday, May 7, 2014 1:13:54 PM UTC-5, [email protected] wrote: > > Hello guys.. I am trying to figure out how to use async. > > I am runing this example : > > var async = require('async'); >> >> for (var i = 0; i < 3; i++) { >> async.series([ >> function(callback){ >> console.log("wait 4 seconds and give error if i = 2, >> value of i :"+ i); >> setTimeout(function () { >> console.log("value of i inside: "+i); >> if(i==2) >> callback("Error", "one"); >> else >> callback(null, 'one'); >> }, 4000); >> }, >> function(callback){ >> callback(null, 'two'); >> } >> ], >> // optional callback >> function(err, results){ >> if(err) console.log("Err: " + err); >> else console.log("Finish series"); >> }); >> }; > > > I hope my output to be other. But i got this one: > > wait 4 seconds and give error if i = 2, value of i :0 >> wait 4 seconds and give error if i = 2, value of i :1 >> wait 4 seconds and give error if i = 2, value of i :2 >> value of i inside: 3 >> Finish series >> value of i inside: 3 >> Finish series >> value of i inside: 3 >> Finish series > > > > In summary I need to make a serie of executions, n times. And in each > time, I will have some parameters changing with each loop (in this example > it's value of i). > > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/700ff752-e506-4650-b861-13f4c13b8476%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
