Skip to content

Instantly share code, notes, and snippets.

@vitalymak
Created August 24, 2016 13:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitalymak/30aa4632a0d8ef792eed93d870ec1761 to your computer and use it in GitHub Desktop.
Save vitalymak/30aa4632a0d8ef792eed93d870ec1761 to your computer and use it in GitHub Desktop.
Bluebird's promise map vs all difference
const Promise = require('bluebird');
const list = [300, 500, 400]
const getMapper = name =>
ms => Promise.delay(ms).then(() => console.log(`${name}: ${ms}ms done in ${Date.now() - start}`));
const start = Date.now();
Promise.map(list, getMapper('map, infinity concurrency'));
Promise.map(list, getMapper('map, 1 concurrent'), {concurrency: 1});
Promise.all(list.map(getMapper('all')));
/* Sample output:
map, infinity concurrency: 300ms done in 309
map, 1 concurrent: 300ms done in 311
all: 300ms done in 312
map, infinity concurrency: 400ms done in 407
all: 400ms done in 407
map, infinity concurrency: 500ms done in 506
all: 500ms done in 506
map, 1 concurrent: 400ms done in 713
map, 1 concurrent: 500ms done in 1215
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment