Created
August 24, 2016 13:22
-
-
Save vitalymak/30aa4632a0d8ef792eed93d870ec1761 to your computer and use it in GitHub Desktop.
Bluebird's promise map vs all difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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