如何在循環的最後一個承諾完成後解決此承諾?NodeJS在完成循環後解析承諾
var foo = function(JSONArray){
return new Promise(function(resolve,reject){
for(var i=0; i < JSONArray.length; i++){
doIntensiveWork(JSONArray[i])
.then(doMoreIntensiveWork) //returns a promise
}
//resolve() after every promise from the loop is fulfilled
})
}
我用Bluebird
' - >'https://github.com/petkaantonov/bluebird/blob/master/API.md#all---promise – 2014-11-24 16:27:27
我覺得青鳥文檔給予足夠的這個解釋更。查看庫中所有酷炫的收集方法,我想你會發現它們非常強大。 – thataustin 2014-11-25 02:36:49