让我们假设以下示例:
var bb = require('bluebird');
var promiseStack = [];
var deferred = bb.defer();
promiseStack.push(deferred.promise);
bb.delay(2500).then(function() {
deferred.resolve();
});
bb.all(promiseStack).then(function() {
console.log('done');
});
为什么不能执行以下操作:
var bb = require('bluebird');
var promiseStack = [];
for(var i = 1; i < 10; i++) {
var deferred = bb.defer();
promiseStack.push(deferred.promise);
bb.delay(2500).then(function() {
deferred.resolve();
});
}
bb.all(promiseStack).then(function() {
console.log('done');
});
它需要aprox。2500 毫秒,但console.log('done')
未被调用。有什么问题,我做错了吗?
最好的,redshark1802