Interface Fork<Success, Failure, Message>

Task is a unit of computation that runs concurrently, a light-weight process (in Erlang terms). You can spawn bunch of them and provided cooperative scheduler will interleave their execution.

Tasks have three type variables first two describing result of the computation Success that corresponds to return type and Failure describing an error type (caused by thrown exceptions). Third type varibale Message describes type of messages this task may produce.

Please note that that TS does not really check exceptions so Failure type can not be guaranteed. Yet, we find them more practical that omitting them as TS does for Promise types.

Our tasks are generators (not the generator functions, but what you get invoking them) that are executed by (library provided) provided scheduler. Scheduler recognizes two special Control instructions yield by generator. When scheduler gets context instruction it will resume generator with a handle that can be used to resume running generator after it is suspended. When suspend instruction is received scheduler will suspend execution until it is resumed by queueing it from the outside event.

Type Parameters

  • Success extends unknown = unknown

  • Failure extends unknown = Error

  • Message extends unknown = never

Hierarchy

Properties

group?: void | TaskGroup<Success, Failure, Message>
id: number
result?: Result<Success, Failure>
status: Status

Methods

  • Returns Controller<Fork<Success, Failure, Message>, never, never>

  • Parameters

    • error: Failure

    Returns Task<void, never, never>

  • Type Parameters

    • U = never

    Parameters

    • handle: ((error) => U)
        • (error): U
        • Parameters

          • error: Failure

          Returns U

    Returns Future<Success | U, never>

  • Parameters

    • value: Success

    Returns Task<void, never, never>

  • Parameters

    • handle: (() => void)
        • (): void
        • Returns void

    Returns Future<Success, Failure>

  • Returns Task<Success, Failure, Message>

  • Parameters

    • value: unknown

    Returns TaskState<Success, Message>

  • Returns Task<void, never, never>

  • Parameters

    • value: Success

    Returns TaskState<Success, Message>

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

    Type Parameters

    • U = Success

    • G = never

    Parameters

    • Optional handle: ((value) => U | PromiseLike<U>)

      The callback to execute when the Promise is resolved.

    • Optional onrejected: ((error) => G | PromiseLike<G>)

      The callback to execute when the Promise is rejected.

    Returns Promise<U | G>

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

  • Parameters

    • error: Failure

    Returns TaskState<Success, Message>

Generated using TypeDoc