async.map不会在nodejs中调用callback

我正在尝试使用async.map,但不能在下面的例子中调用callback的一些不明原因,函数d应该显示数组r,但它没有。 实际上就好像d从来没有叫过。

我一定在做一些非常错误的事情,但是搞不清楚

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); 

预先感谢您的帮助

       

网上收集的解决方案 "async.map不会在nodejs中调用callback"

 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);