I am trying to use async.map but can't get it to call the callback for some unknwon reason in the below example, the function d should display the array r but it just does not. actually it is as if d was never called.
I must be doing something really wrong but can't figure out what
async = require('async');
a= [ 1,2,3,4,5];
r=new Array();
function f(callback){
return function(e){
e++;
callback(e);}
}
function c(data){ r.push(data); }
function d(r){ console.log(r);}
async.map(a,f(c),d);
thank you in advance for your help
var async = require('async');
//This is your async worker function
//It takes the item first and the callback second
function addOne(number, callback) {
//There's no true asynchronous code here, so use process.nextTick
//to prove we've really got it right
process.nextTick(function () {
//the callback's first argument is an error, which must be null
//for success, then the value you want to yield as a result
callback(null, ++number);
});
}
//The done function must take an error first
// and the results array second
function done(error, result) {
console.log("map completed. Error: ", error, " result: ", result);
}
async.map([1,2,3,4,5], addOne, done);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With