javascript - Is Node.js native Promise.all processing in parallel or sequentially? -


i clarify point, documentation not clear it;

q1: promise.all(iterable) processing promises sequentially or in parallel? or, more specifically, equivalent of running chained promises

p1.then(p2).then(p3).then(p4).then(p5).... 

or other kind of algorithm p1, p2, p3, p4, p5, etc. being called @ same time (in parallel) , results returned resolve (or 1 rejects)?

q2: if promise.all runs in parallel, there convenient way run iterable sequencially?

note: don't want use q, or bluebird, native es6 specs.

is promise.all(iterable) executing promises?

no, promises cannot "be executed". start task when being created - represent results - , you executing in parallel before passing them promise.all.

promise.all await multiple promises. doesn't care in order resolve, or whether computations running in parallel.

is there convenient way run iterable sequencially?

if have promises, can't promise.all([p1, p2, p3, …]) (which not have notion of sequence). if have iterable of asynchronous functions, can indeed run them sequentially. need

[fn1, fn2, fn3, …] 

to

fn1().then(fn2).then(fn3).then(…) 

and solution using array::reduce:

iterable.reduce((p, fn) => p.then(fn), promise.resolve()) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -