The type of the action's result value
Optional context type passed through to callbacks
Either a Promise or a function that receives an AbortController and returns a Promise
Optional configuration:
Promise resolving to a TimeoutResult containing:
// With a function that can be aborted
const result = await timeouted(
async (controller) => {
return fetch(url, { signal: controller.signal });
},
{ timeout: 5000 }
);
if (isSuccess(result)) {
console.log('Request completed:', result.value);
} else if (isTimeout(result)) {
console.log('Request timed out after', result.duration, 'ms');
}
// With a direct promise
const result2 = await timeouted(
fetch(url),
{ timeout: 3000 }
);
Executes an action with comprehensive timeout and abort handling.
Wraps a promise or async function with timeout, abort signal, and error handling capabilities. The action can be controlled via AbortController and will properly clean up resources.