( fn: (signal: AbortSignal) => Promise<T>, timeout: number, errorOrFnName?: string | (() => Error), onAbort?: () => void, )
| 79 | * |
| 80 | * */ |
| 81 | export async function executeTimeout<T>( |
| 82 | fn: (signal: AbortSignal) => Promise<T>, |
| 83 | timeout: number, |
| 84 | errorOrFnName?: string | (() => Error), |
| 85 | onAbort?: () => void, |
| 86 | ) { |
| 87 | const errorFn = |
| 88 | typeof errorOrFnName === 'function' |
| 89 | ? errorOrFnName |
| 90 | : () => new TimeoutError(`Timeout running ${errorOrFnName ?? 'function'} after ${timeout}ms.`); |
| 91 | const task = new TimeoutTask(fn, timeout, errorFn, onAbort); |
| 92 | return await task.exec(); |
| 93 | } |
| 94 | |
| 95 | /** Returns a promise that rejects after the given timeout */ |
| 96 | export function timeoutPromise(timeoutMs: number, errorMessage?: string) { |
no test coverage detected