Uneventful
    Preparing search index...

    A task is a cancellable future: i.e. something that produces an async result, but whose work can be aborted.

    interface Task<T = void> extends Cancellable, Future<T> {}

    Type Parameters

    • T = void

      The type of result the task will produce. A type of never means the activity never produces a value, but instead will run until it is cleaned up, e.g. due to being canceled, ended with an error, etc.

    Hierarchy (View Summary)

    Index

    Execution Control

    Obtaining Results

    Other

    Execution Control

    end: () => void

    Release all resources held by the task or context.

    Arrange for all cleanup functions and result consumers added to the context (via release, must, do, etc.) be called in the appropriate order. When the call to end() returns, all child tasks will have been notified of their cancellation. (But not all of their cleanups or result consumers may have run yet, in the event that another task's end() is in progress when this method is called.)

    If any cleanup callbacks throw exceptions, they're sent to root.asyncThrow(), which by default converts them to unhandled promise rejections. This ensures all of the callbacks will be run, even if one throws an error. (And none of the errors will be missed.)

    Note: this method is a bound function, so you can pass it as a callback to another task, event source, etc.

    Obtaining Results

    • An iterable suitable for use with yield * (in a coroutine) to obtain a result.

      Returns Coroutine<T>

    • Invoke a callback with the result.

      Callbacks are executed in FIFO order after any cleanups for the producing task have run, and before any asynchronous (Promise) callbacks run. You should only use this (and other Future methods) to obtain a result, not to perform cleanups. (That's what .Context.must() and .Context.release() callbacks are for.)

      Parameters

      • action: (res: Result<T>) => unknown

      Returns this

      The .onError(), .onValue(), and .onCancel() methods provide shortcuts for creating do callbacks that only run under specific end conditions.

    • Invoke a callback if the producing task is canceled.

      This is shorthand for a .do() callback that checks for a cancellation, so it uses the same relative order and runs in the same group as other .do callbacks.

      Parameters

      • cb: () => unknown

        The callback run on cancellation

      Returns this

    • Invoke a callback upon result if the result is an error.

      This is shorthand for a .do() callback that checks for an error and marks it handled, so it uses the same relative order and runs in the same group as other .do callbacks.

      Parameters

      • cb: (err: any) => unknown

        A callback that will receive the error

      Returns this

    • Invoke a callback upon result if the result is a success/value.

      This is shorthand for a .do() callback that checks for a success/value result, so it uses the same relative order and runs in the same group as other .do callbacks.

      Parameters

      • cb: (val: T) => unknown

        A callback that will receive the value

      Returns this

    • The result of the future (canceled, returned value, or error), or undefined if there's no result yet.

      If undefined, this also acts as a reactive value: the calling reactive function or effect (if any) will recalculate when the future settles, with the updated result.

      Returns Result<T> | undefined

    Other

    "[toStringTag]": string
    • Attaches a callback for only the rejection of the Promise.

      Type Parameters

      • TResult = never

      Parameters

      • Optionalonrejected: ((reason: any) => TResult | PromiseLike<TResult>) | null

        The callback to execute when the Promise is rejected.

      Returns Promise<T | TResult>

      A Promise for the completion of the callback.

    • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

      Parameters

      • Optionalonfinally: (() => void) | null

        The callback to execute when the Promise is settled (fulfilled or rejected).

      Returns Promise<T>

      A Promise for the completion of the callback.

    • Attaches callbacks for the resolution and/or rejection of the Promise.

      Type Parameters

      • TResult1 = T
      • TResult2 = never

      Parameters

      • Optionalonfulfilled: ((value: T) => TResult1 | PromiseLike<TResult1>) | null

        The callback to execute when the Promise is resolved.

      • Optionalonrejected: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null

        The callback to execute when the Promise is rejected.

      Returns Promise<TResult1 | TResult2>

      A Promise for the completion of which ever callback is executed.