petkaantonov / bluebird

:bird: :zap: Bluebird is a full featured promise library with unmatched performance.
http://bluebirdjs.com
MIT License
20.44k stars 2.34k forks source link

Promise.map concurrency execution order #708

Closed henryqdineen closed 9 years ago

henryqdineen commented 9 years ago

I am having a problem with the concurrency option for Promise.map. I'm my code I want the order of execution of promises to match the order of the input (in my case optimizing file reads from a CDROM)

Consider this example:

Promise.map([1, 2, 3, 4, 5], function(val) {
    return new Promise.delay(100).then(function() {
        console.log(val);
    });
}, {concurrency: 2});

The console output of this code will be 1 2 5 4 3

spion commented 5 days ago

http://bluebirdjs.com/docs/api/promise.map.html#:~:text=The%20order%20map%20calls%20the%20mapper%20function%20on%20the%20array%20elements%20is%20not%20specified%2C%20there%20is%20no%20guarantee%20on%20the%20order%20in%20which%20it%27ll%20execute%20the%20maper%20on%20the%20elements

brian-murphy commented 5 days ago

Thanks for the response. I was hoping for a line like "Execution order is not guaranteed" in the JS doc, but as I'm looking at the code I see that's actually in a different project https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/bluebird/v2/index.d.ts#L304