I am trying to execute a sequence of promises in order, only going to the next after the previous is resolved. From the Bluebird docs:
The iterator will not be called for the element until its previous element, and the promise returned by the iterator for this element will be fulfilled. http://bluebirdjs.com/docs/api/promise.mapseries.html
var Promise = require('bluebird'); function test(time) { return new Promise(function(resolve, reject) { setTimeout(function() { console.log(time); resolve(time); }, time); }); } Promise.mapSeries([test(2000), test(1000), test(500), test(3000)], function(a) { return a; }).then(function(results) { console.log(results); });
I expect console.log inside the test function to display: 2000, 1000, 500, 3000 in that order. I expect that because, as the docs say, each element only goes after the previous one is allowed. Instead, I get 500, 1000, 2000, 3000, which reflects the fact that all functions are called instantly. Moreover, the results show the results in the order in which they were called, although this does not matter at this point.
Do I really understand something?
source share