Since you are using Bluebird JS, this can be done in a simple way.
In version 2.0, Bluebird introduced the Promise.each method, which does this because the loop loop is then quite simple, but since it is so common and requested from time to time, it was added as its own method.
function foo(item, ms){ // note bluebird has a delay method return Promise.delay(ms, item).then(console.log.bind(console)) } var items = ['one', 'two', 'three']; Promise.each(items, function(item, i){ return foo(item, (items.length - i) * 1000) });
Which gives the same result as another answer, with only fewer lines of code, and also allows Bluebird to perform iteration optimization.
source share