Affichage des articles dont le libellé est Not all Promises returned. Afficher tous les articles
Affichage des articles dont le libellé est Not all Promises returned. Afficher tous les articles

lundi 29 décembre 2014

Not all Promises returned

Run the code below:

Code:



var count = 0,
promise = new Ext.Promise(),
syncEngines = ['engine1', 'engine2', 'engine3', 'engine4'],
syncTimestamps = Ext.space.SecureLocalStorage.get('syncTimestamps'),
checkDone = function() {
if(count==syncEngines.length) {
promise.fulfill(new Date());
}
};
Ext.each(syncEngines, function(engine) {
console.log('Getting timestamp for: ' + engine);
syncTimestamps.get(engine).then(function(dt) {
count++;
console.log('Promise return: ' + count);
checkDone();
});
});
return promise;

Here's the result:


Code:



[Log] Getting timestamp for: engine1 (Main.js, line 273)
[Log] Getting timestamp for: engine2 (Main.js, line 273)
[Log] Getting timestamp for: engine3 (Main.js, line 273)
[Log] Getting timestamp for: engine4 (Main.js, line 273)
[Log] Promise return: 1 (Main.js, line 276)
[Log] Promise return: 2 (Main.js, line 276)
[Log] Promise return: 3 (Main.js, line 276)

Never the 4th one back...



Not all Promises returned