mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
14 lines
283 B
TypeScript
14 lines
283 B
TypeScript
import asyncWait from './asyncWait'
|
|
|
|
const asyncTimeout = <T>(fn: () => Promise<T>, ms: number) => {
|
|
return Promise.race([
|
|
fn(),
|
|
async () => {
|
|
await asyncWait(ms)
|
|
throw new Error('timeout')
|
|
},
|
|
])
|
|
}
|
|
|
|
export default asyncTimeout
|