Skip to content

Instantly share code, notes, and snippets.

@cavinsmith
Last active November 16, 2017 05:17
Show Gist options
  • Save cavinsmith/125a4abdbbdf88a51ed25d9cb5e00454 to your computer and use it in GitHub Desktop.
Save cavinsmith/125a4abdbbdf88a51ed25d9cb5e00454 to your computer and use it in GitHub Desktop.
promiseAny
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