use*_*342 5 javascript node.js promise bluebird
for (var i in listofInstances) {
cleanupInstance(listofInstances[ i ])
.then(function () {
console.log("Done" + listofInstances[ i ])
});
}
Run Code Online (Sandbox Code Playgroud)
cleanupInstance也是一个承诺链.但是,目前我的for循环在整个promise链完成之前进入下一次迭代.有没有办法宣传循环?我正在使用Bluebird库(nodejs)进行承诺.
你可以使用.each:
var Promise = require('bluebird');
...
Promise.each(listofInstances, function(instance) {
return cleanupInstance(instance).then(function() {
console.log('Done', instance);
});
}).then(function() {
console.log('Done with all instances');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3900 次 |
| 最近记录: |