async.series() executes some asynchronous functions one after the other, in the same order as specified by the array. If you want to repeat the same asynchronous function multiple times, you can choose between async.times() and async.timesSeries().
2014-05-07 20:13 GMT+02:00 <[email protected]>: > 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/57fd29cf-0a34-4469-94fc-a54be8eaf0cb%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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/CABQ8R0wNh%3D53S9rTmfiU%2BP3x4fOQOnnEJSYQiRWqUiENEhVHww%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
