Promise.any
Promise.any
Implement your own version of Promise.any that returns the first fulfilled promise.
Requirements:
- Return a Promise that resolves with the first fulfilled promise value
- Ignore rejected promises unless all promises reject
- If all promises reject, reject with AggregateError
Example:
const p1 = Promise.reject('error1');
const p2 = new Promise(resolve => setTimeout(() => resolve('success'), 100));
promiseAny([p1, p2]).then(value => {
console.log(value); // 'success'
});
Examples:
Input 1:
{"value":"success"}Output 1:
"success"Loading editor...
Run your code to see results
Click the Run button above