Last active
November 16, 2017 05:17
-
-
Save cavinsmith/125a4abdbbdf88a51ed25d9cb5e00454 to your computer and use it in GitHub Desktop.
promiseAny
This file contains hidden or 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 test = (type, timeout) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
return (type === 'resolve' ? resolve : reject)(`${type} -> ${timeout}`) | |
}, timeout) | |
}) | |
} | |
Promise.any([test('resolve', 1000), test('resolve', 2000), test('reject', 500)]) | |
.then(result => console.log(`then: ${result}`)) | |
.catch(error => console.log(`catch: ${error}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment