A task that can be cancelled.
We recommend using the Task.from method to create a task. When creating subtasks, pass the same controller to all subtasks.
Task.from
const parent = Task.from((controller) => { const child1 = Task.from(() => { ... }, controller); const child2 = Task.from(() => { ... }, controller);});parent.cancel(); Copy
const parent = Task.from((controller) => { const child1 = Task.from(() => { ... }, controller); const child2 = Task.from(() => { ... }, controller);});parent.cancel();
This will cancel all subtasks when the parent is cancelled.
The type of the task result
Optional
Readonly
Whether the task has completed.
The result of the task.
Cancels the task.
Cancels the task and waits for it to complete.
The timeout in milliseconds
The result status of the task (timeout, completed, aborted)
Static
Creates a new task from a function.
The function to run
The abort controller to use
A new task
A task that can be cancelled.
We recommend using the
Task.from
method to create a task. When creating subtasks, pass the same controller to all subtasks.Example
This will cancel all subtasks when the parent is cancelled.