Function: raceWithFallback()
ts
function raceWithFallback<T>(promises, fallback): Promise<T>;Races multiple promises and returns the first resolved value, or fallback if all reject. 竞争多个 Promise,返回第一个 resolve 的值,若全部失败则返回 fallback。
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
promises | Promise<T>[] |
fallback | T |
Returns
Promise<T>
Example
ts
const result = await raceWithFallback([Promise.resolve('first'), new Promise(() => {})], 'fallback', 50)
result // => 'first'Since
1.0.0