API Reference / @evolu/common / Promise / withTimeout
Function: withTimeout()
function withTimeout<T, E>(fn, timeoutMs): Promise<Result<T,
| TimeoutError
| E>>;
Defined in: packages/common/src/Promise.ts:277
Wraps an async function with a timeout, returning Result that fails with TimeoutError if the timeout is exceeded. The provided function must accept an AbortSignal and return a Result.
Example
const fetchWithTimeout = () =>
withTimeout((signal) => fetch("url", signal), 5000);
const result = await retry(fetchWithTimeout, { maxRetries: 3 });
Type Parameters
Type Parameter |
---|
T |
E |
Parameters
Parameter | Type |
---|---|
fn | (signal ) => Promise <Result <T , E >> |
timeoutMs | number |
Returns
Promise
<Result
<T
,
| TimeoutError
| E
>>