Promises

Promises

Are objects responsible for modeling asyncronous behaviour, allowing its treatment in a more direct and easy way.

Promise.all()

Promise.all([
    promise1,
    promise2,
    ...
]).then((values) => {
    const [p1Return, p2Return, ...] = values;

    ...
}).catch((e) => {
    ...
});

Promise.race()

Executes multiple promises at the same time, but returns only the first one that finishes.

Promise.race([
   promise1,
   promise2,
   ...
]).then((value) => {
   ...
}).catch((e) => {
   ...
});

Last updated