implement Promise.any()
2022年5月1日小于 1 分钟
Promise.any()
implement Question
Promise.any() takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfils, returns a single promise that resolves with the value from that promise
- from MDN
Can you implement a any()
to work the same as Promise.any()
?
note
AggregateError
is not supported in Chrome yet, but you can still use it in your code since we will add the Class into your code. Do something like following:
new AggregateError(
'No Promise in Promise.any was resolved',
errors
)
Code
/**
* @param {Array<Promise>} promises
* @return {Promise}
*/
function any(promises) {
// your code here
}