2016-04-04 93 views
-1

所有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

那麼,如果你只需要執行一個函數,爲什麼不只是傳遞一個回調?

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

問題是我需要通過應用程序以通用的方式處理響應。所以這不是... – zatziky

+0

男人,你是對的!我開始以過於複雜的方式思考。 – zatziky