让 Promise 与超时竞争,超时后抛出错误
目标 Promise
超时毫秒数,超时后以 Error('Timeout after <ms>ms') reject
Error('Timeout after <ms>ms')
与超时竞速的新 Promise
const result = await withTimeout(fetchData(), 5000) Copy
const result = await withTimeout(fetchData(), 5000)
让 Promise 与超时竞争,超时后抛出错误