use*_*050 9 asynchronous callback node.js
我试图使用async.map,但是在下面的例子中,由于某些unknwon原因无法让它调用回调,函数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);
预先感谢您的帮助
Pet*_*ons 14
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);
| 归档时间: | 
 | 
| 查看次数: | 7850 次 | 
| 最近记录: |