Repozytorium Web Developera

JavaScript - asynchronity and Promises

Promises

Promise.all() method

Only parameter of this method is iterable which means an array for example. This method is processing all promises in parallel and waits until they are all solved.

Processing Promises sequentially


const iterable = [fn1, fn2, fn3, …]
iterable.reduce((p, fn) => p.then(fn), Promise.resolve())
// or
for (let i = 0; i < iterable.length; i++) {
    await iterable[i]()
}
// or
for (value of iterable) {
    await value()
}

More information about processing them sequentially can be find here.