# TaskInstance

New task instance is created via performing a task.

const task = useTask(function*(signal, a, b) {
  /* ... */
const taskInstance = task.perform(1, 2);

# value

T | null

The value of an instance is what the perform function returns.

const taskInstance = task.perform();
await taskInstance;

# error

any | null

Instance saves in error whatever was thrown during the perform call. Read more about handling errors.

const task = useTask(function*() {
  throw new Error("You shall not pass");

const instance = task.perform();

# hasStarted


Instance is started immediately after a task is performed unless it was enqueued or dropped or immediately canceled.

# isRunning


Instance is running unless it's finished, dropped or enqueued.

# isFinished


Instance is finished if it has resolved a value or threw an error

# isError


if (instance.isError) {

# isSuccessful


Instance is successful if it is finished and there's no error

# isCanceled


Instance is canceled if it was cancelled implicitly (via cancel on unmount) or explicitly via cancel() or cancelAll().

# isDropped


Instance may be dropped if the task has drop() or keepLatest() concurrency policy.

# isEnqueued


Instance may be enqueued if the task has enqueue() or keepLatest() concurrency policy.

# then()

(onfulfilled: onFulfilled<T>, onrejected?: onRejected) => Promise<any>

Allows to use the task in a PromiseLike way. Returns a promise which allows chaining just like with regular promises. This also allows the instance to be awaited.

const instance = task.perform();
instance.then((resultValue) => {
  // ...

// or just await

const value = await instance;

Read more about composing tasks.

# catch()

(onrejected?: onRejected) => any

Allows to catch errors that were thrown during the perform call.

const instance = task.perform();
instance.catch((error) => {

// or just await with try catch

try {
  const value = await instance;
} catch (error) {

# finally()

() => any

finally is called either way not matter if instance resolved or rejected.

# status

"running" | "enqueued" | "canceled" | "canceling" | "dropped" | "error" | "success"

status might be useful for debugging purposes.

  <div>{{ myTask.status }}</div>

# canceledOn()

(signal: AbortSignalWithPromise) => TaskInstance<T>

This is used for some cases when cancelation does not cascade. See details here.

# id


id might be useful sometimes for debugging purposes as it's simply the index of the task instance within the task.