Timeouts
Network slowdowns or server hangs can lock user interfaces indefinitely. ngx-task provides built-in timeout options.
Simple Timeout (ms)
Pass a number in milliseconds to timeout:
const fetchOrder = createTask( async (orderId: string, { signal }) => { return api.getOrder(orderId, { signal }); }, { timeout: 10_000, // Automatically aborts if execution exceeds 10 seconds },);When a timeout occurs:
context.signalis aborted with aTaskTimeoutError.task.error()is updated withcode: 'TASK_TIMEOUT'.- The execution Promise rejects with
TaskTimeoutError.
Detailed Timeout Options
You can pass a TaskTimeoutOptions object for granular control:
const uploadTask = createTask(uploadHandler, { timeout: { duration: 30_000, // 30 seconds limit reason: 'File upload timed out after 30 seconds', },});