promise any 28 29

Solutions on MaxInterview for promise any 28 29 by the best coders in the world

showing results for - "promise any 28 29"
Renata
09 Nov 2017
1//Promise.any() is useful to perform independent async operations
2//in parallel in a race manner, 
3//to get the value of any first successfully resolved promise.
4//read more https://dmitripavlutin.com/promise-any/
5
6const promise1 = Promise.reject(0);
7const promise2 = new Promise((resolve) => setTimeout(resolve, 100, 'quick'));
8const promise3 = new Promise((resolve) => setTimeout(resolve, 500, 'slow'));
9
10const promises = [promise1, promise2, promise3];
11
12Promise.any(promises).then((value) => console.log(value));
13
14// expected output: "quick"