异步:运行单一功能

时间:2016-04-04 10:43:18

标签: node.js express async.js

所有async.js运算符似乎仅用于集合。有没有办法运行这段代码:

async.series([
            function (callback) {
              TripDao.getTrip(callback);
            }],
            function done(error, result) {
              var trip = result[0];
              // things to do with trip
            }
    );

这样吗?

async.runSingle(function(callback){
          TripDao.getTrip(callback);
       },
       function done(error, trip){
          // things to do with trip
       }
);

1 个答案:

答案 0 :(得分:1)

如果你只需要执行一个函数,为什么不直接传递一个回调?

TripDao.getTrip(function (error, trip) {
    // things to do with trip
});