I have the following code, however, the final / result is being done async callback sequence.
function dogetcomp (sid, acb) {var comp = []; ({Sid: sid}) Sort ({date: -1}) range (25) .exec (function (mistake, comps) {for (var i = 0; i & lt; comps.length; i ++) { Function (cnt) {var d = {}; async.series ([function (cb) {user.findOne ({uid: comps [cnt] .uid}, function (mistake, u) {d.uname = U.name ; D.when = comps [cnt] .date.toString (); cb ();})}, function (cb) {rec.findOne ({type: comps [cnt] .type}, function (gal, cue ) {D.qname = q.name; cb}}}}, function (race) {console.log (cnt); comp.push (d); if (comp.length == comps length) {acb ( Blank, comp);}});}} (i); }}); }
The result is 1,2,3,0 being printed and the order is getting out of order. Why is the first entry being finalized? Is this a better way to loop it?
Normal will not wait until the loop is ready while you are using the Ashkin Library To do this, you can also change it better for the loop.
With async.eachSeries, in the callback of async.series, callback calls for async.eachSeries, then it will execute in good order. Async.eachSeries ([0,1,2,3], function (number, call) {async.series ([], function (call) {call ()});}, function (error) {console.log ( 'Done');})
Comments
Post a Comment