Skip to content

TaskDispatcher

The TaskDispatcher port decides how a reserved invocation runs; the scheduler decides what runs. An invocation is one fiber: a run invocation executes a task’s phases in sequence, and an abort invocation runs its abort handler once.

inProcess keeps the fibers in a FiberMap keyed by task ID, in the scope of the layer. Closing the layer’s scope interrupts them all, which is pi’s close().

Since v0.0.0


Signature

export interface InProcessOptions {
/**
* How many invocations may run at once; the rest wait for a free slot. Default: unlimited. An invocation that
* waits for another task inside its handler (`TaskRuntime.waitForTask`) keeps its slot, so a limit smaller than the
* deepest chain of such waits can stall; `Next.wait` frees the slot.
*/
readonly concurrency?: number
}

Source

Since v0.0.0

What the dispatcher is told about the invocation it starts.

Signature

export interface InvocationInfo {
readonly taskId: TaskId
/** The task definition's name. */
readonly kind: string
readonly mode: "run" | "abort"
}

Source

Since v0.0.0

A started invocation, bound to that one invocation and no other.

Signature

export interface StartedInvocation {
/**
* Interrupt the invocation and wait until it is gone, including while it still waits for a slot and has not begun.
* A later invocation of the same task is never affected.
*/
readonly interrupt: Effect.Effect<void>
}

Source

Since v0.0.0

Signature

declare class TaskDispatcher

Source

Since v0.0.0

Signature

export interface TaskDispatcherShape {
/**
* Start `work` and return at once. `work` cannot fail. A task has at most one invocation; starting another for the
* same task replaces it.
*/
readonly start: (invocation: InvocationInfo, work: Effect.Effect<void>) => Effect.Effect<StartedInvocation>
/** Interrupt every invocation and wait until they are gone. */
readonly interruptAll: Effect.Effect<void>
}

Source

Since v0.0.0

Run invocations as fibers of the layer’s scope.

Signature

declare const inProcess: (options?: InProcessOptions) => Layer.Layer<TaskDispatcher>

Source

Since v0.0.0