( promise: Promise<T>, error?: string | Error, timeoutMillis = 5000, )
| 13 | } |
| 14 | |
| 15 | export async function timeoutError<T>( |
| 16 | promise: Promise<T>, |
| 17 | error?: string | Error, |
| 18 | timeoutMillis = 5000, |
| 19 | ): Promise<T> { |
| 20 | if (typeof error === "string") error = new Error(error); |
| 21 | return Promise.race<T>([ |
| 22 | promise, |
| 23 | new Promise((resolve, reject) => { |
| 24 | setTimeout(() => reject(error || new Error("Operation timed out.")), timeoutMillis); |
| 25 | }), |
| 26 | ]); |
| 27 | } |
no test coverage detected
searching dependent graphs…