promise allsetteled

Solutions on MaxInterview for promise allsetteled by the best coders in the world

showing results for - "promise allsetteled"
Jerónimo
14 Jun 2020
1/*/The Promise.allSettled() method returns a promise that resolves
2after all of the given promises have either fulfilled or rejected,
3with an array of objects that each describes the outcome of each promise.
4*/
5const promise1 = Promise.resolve(3);
6const promise2 = new Promise((resolve, reject) => setTimeout(reject, 100, 'foo'));
7const promises = [promise1, promise2];
8
9Promise.allSettled(promises).
10  then((results) => results.forEach((result) => console.log(result)));
11
12// expected output:
13>  { status: "fulfilled", value: 3 }
14>  { status: "rejected", reason: "foo" }
15