Created
May 18, 2019 02:31
-
-
Save dance2die/e59a0f90b6a0ea585520b994652bfb55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const promiseWillFulfill = [ | |
new Promise((resolve, reject) => setTimeout(reject, 250, 'π')), | |
new Promise((resolve, reject) => setTimeout(resolve, 150, 'π')), | |
new Promise((resolve, reject) => setTimeout(resolve, 1, 'π')), | |
] | |
Promise.race(promiseWillFulfill) | |
.then(value => console.log(`The humanity survives "${value}"`)) | |
.catch(error => console.log(`Won't be called as π will win the race`)) | |
const promiseWillReject = [ | |
new Promise((resolve, reject) => setTimeout(resolve, 250, 'π')), | |
new Promise((resolve, reject) => setTimeout(reject, 1, 'π')), | |
new Promise((resolve, reject) => setTimeout(resolve, 250, 'π')), | |
] | |
Promise.race(promiseWillReject) | |
.then(value => console.log(`This won't be called...="${value}"`)) | |
.catch(error => console.log(`The humanity is doomed...="${error}"`)) | |
const promisesWithOUTReject = [ | |
new Promise(resolve => setTimeout(resolve, 350, 'one')), | |
new Promise(resolve => setTimeout(resolve, 250, 'two')), | |
new Promise(resolve => setTimeout(resolve, 150, 'three')), | |
] | |
Promise.race(promisesWithOUTReject) | |
.then(value => console.log(`Promise without reject="${value}"`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The humanity survives "π" | |
The humanity is doomed...="π" | |
Promise without reject="three" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment