Skip to content

DurableDeferred.ts

Defines named wait points for durable workflow executions.

A DurableDeferred has a stable name and schemas for the value that will be recorded later. Workflows can await it, suspend when no result exists yet, and resume after its result is recorded. Tokens identify the workflow name, execution id, and deferred name so external code can complete the correct wait point later.

Since v4.0.0



Waits for the durable deferred, suspending the current workflow when no persisted completion is available.

Signature

declare const await: <Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>
) => Effect.Effect<
Success["Type"],
Error["Type"],
WorkflowEngine | WorkflowInstance | Success["DecodingServices"] | Error["DecodingServices"]
>

Source

Since v4.0.0

Completes the durable deferred identified by a token with the supplied exit, encoding the result through the deferred schemas.

Signature

declare const done: {
<Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {
readonly token: Token
readonly exit: Exit.Exit<Success["Type"], Error["Type"]>
}): (
self: DurableDeferred<Success, Error>
) => Effect.Effect<void, never, WorkflowEngine | Success["EncodingServices"] | Error["EncodingServices"]>
<Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>,
options: { readonly token: Token; readonly exit: Exit.Exit<Success["Type"], Error["Type"]> }
): Effect.Effect<void, never, WorkflowEngine | Success["EncodingServices"] | Error["EncodingServices"]>
}

Source

Since v4.0.0

Completes the durable deferred identified by a token with a typed failure.

Signature

declare const fail: {
<Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {
readonly token: Token
readonly error: Error["Type"]
}): (self: DurableDeferred<Success, Error>) => Effect.Effect<void, never, WorkflowEngine | Error["EncodingServices"]>
<Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>,
options: { readonly token: Token; readonly error: Error["Type"] }
): Effect.Effect<void, never, WorkflowEngine | Error["EncodingServices"]>
}

Source

Since v4.0.0

Completes the durable deferred identified by a token with a failure cause.

Signature

declare const failCause: {
<Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {
readonly token: Token
readonly cause: Cause.Cause<Error["Type"]>
}): (self: DurableDeferred<Success, Error>) => Effect.Effect<void, never, WorkflowEngine | Error["EncodingServices"]>
<Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>,
options: { readonly token: Token; readonly cause: Cause.Cause<Error["Type"]> }
): Effect.Effect<void, never, WorkflowEngine | Error["EncodingServices"]>
}

Source

Since v4.0.0

Runs an effect and records its exit into the durable deferred, resuming workflows that are waiting on that deferred.

Signature

declare const into: {
<Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>
): <R>(
effect: Effect.Effect<Success["Type"], Error["Type"], R>
) => Effect.Effect<
Success["Type"],
Error["Type"],
R | WorkflowEngine | WorkflowInstance | Success["DecodingServices"] | Error["DecodingServices"]
>
<Success extends Schema.Constraint, Error extends Schema.Constraint, R>(
effect: Effect.Effect<Success["Type"], Error["Type"], R>,
self: DurableDeferred<Success, Error>
): Effect.Effect<
Success["Type"],
Error["Type"],
R | WorkflowEngine | WorkflowInstance | Success["DecodingServices"] | Error["DecodingServices"]
>
}

Source

Since v4.0.0

Completes the durable deferred identified by a token with a successful value.

Signature

declare const succeed: {
<Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {
readonly token: Token
readonly value: Success["Type"]
}): (
self: DurableDeferred<Success, Error>
) => Effect.Effect<void, never, WorkflowEngine | Success["EncodingServices"]>
<Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>,
options: { readonly token: Token; readonly value: Success["Type"] }
): Effect.Effect<void, never, WorkflowEngine | Success["EncodingServices"]>
}

Source

Since v4.0.0

Creates a named durable deferred with optional success and error schemas for persisted completion.

Signature

declare const make: <Success extends Schema.Constraint = Schema.Void, Error extends Schema.Constraint = Schema.Never>(
name: string,
options?: { readonly success?: Success | undefined; readonly error?: Error | undefined }
) => DurableDeferred<Success, Error>

Source

Since v4.0.0

Type-erased durable deferred shape for APIs that only need the deferred identity and name.

Signature

export interface Any {
readonly [TypeId]: typeof TypeId
readonly name: string
}

Source

Since v4.0.0

Type-erased durable deferred shape that also exposes success, error, and exit schemas.

Signature

export interface AnyWithProps {
readonly [TypeId]: typeof TypeId
readonly name: string
readonly successSchema: Schema.Top
readonly errorSchema: Schema.Top
readonly exitSchema: Schema.Exit<any, any, any>
}

Source

Since v4.0.0

Named durable deferred value whose completion is persisted by the workflow engine and encoded with success and error schemas.

Signature

export interface DurableDeferred<Success extends Schema.Constraint, Error extends Schema.Constraint = Schema.Never> {
readonly [TypeId]: typeof TypeId
readonly name: string
readonly successSchema: Success
readonly errorSchema: Error
readonly exitSchema: Schema.Exit<Schema.Top, Schema.Top, Schema.Top>
readonly withActivityAttempt: Effect.Effect<DurableDeferred<Success, Error>>
}

Source

Since v4.0.0

Runs effects as a durable race, returning a previously persisted result when present or completing a named deferred with the first result.

Signature

declare const raceAll: <
const Effects extends NonEmptyReadonlyArray<Effect.Effect<any, any, any>>,
Success extends Schema.Schema<Effect.Success<Effects[number]>>,
Error extends Schema.Schema<Effect.Error<Effects[number]>>
>(options: {
name: string
success: Success
error: Error
effects: Effects
}) => Effect.Effect<
Effect.Success<Effects[number]>,
Effect.Error<Effects[number]>,
| Effect.Services<Effects[number]>
| Success["DecodingServices"]
| Success["EncodingServices"]
| Error["DecodingServices"]
| Error["EncodingServices"]
| WorkflowEngine
| WorkflowInstance
>

Source

Since v4.0.0

Schema for branded durable deferred tokens.

Signature

declare const Token: Schema.brand<Schema.String, "~effect/workflow/DurableDeferred/Token">

Source

Since v4.0.0

Branded string token identifying a durable deferred for a workflow execution.

Signature

type Token = Brand.Branded<string, TokenTypeId>

Source

Since v4.0.0

Schema for a decoded durable deferred token containing the workflow name, execution ID, and deferred name.

Signature

declare class TokenParsed

Source

Since v4.0.0

Creates a token for a durable deferred using the current workflow instance’s workflow name and execution ID.

Signature

declare const token: <Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>
) => Effect.Effect<Token, never, WorkflowInstance>

Source

Since v4.0.0

Creates a durable deferred token from an explicit workflow, execution ID, and deferred name.

Signature

declare const tokenFromExecutionId: {
(options: {
readonly workflow: Workflow.Any
readonly executionId: string
}): <Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>
) => Token
<Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>,
options: { readonly workflow: Workflow.Any; readonly executionId: string }
): Token
}

Source

Since v4.0.0

Creates a durable deferred token by deriving the workflow execution ID from the supplied workflow payload.

Signature

declare const tokenFromPayload: {
<W extends Workflow.Any>(options: {
readonly workflow: W
readonly payload: Workflow.PayloadSchema<W>["~type.make.in"]
}): <Success extends Schema.Constraint, Error extends Schema.Constraint>(
self: DurableDeferred<Success, Error>
) => Effect.Effect<Token>
<Success extends Schema.Constraint, Error extends Schema.Constraint, W extends Workflow.Any>(
self: DurableDeferred<Success, Error>,
options: { readonly workflow: W; readonly payload: Workflow.PayloadSchema<W>["~type.make.in"] }
): Effect.Effect<Token>
}

Source

Since v4.0.0

Runtime brand identifier for durable deferred tokens.

Signature

declare const TokenTypeId: "~effect/workflow/DurableDeferred/Token"

Source

Since v4.0.0

Type-level brand identifier for Token values.

Signature

type TokenTypeId = typeof TokenTypeId

Source

Since v4.0.0