DurableDeferred.ts
DurableDeferred.ts overview
Section titled “DurableDeferred.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”combinators
Section titled “combinators”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"]>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"]>}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"]>}Since v4.0.0
failCause
Section titled “failCause”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"]>}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"] >}Since v4.0.0
succeed
Section titled “succeed”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"]>}Since v4.0.0
constructors
Section titled “constructors”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>Since v4.0.0
models
Section titled “models”Any (interface)
Section titled “Any (interface)”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}Since v4.0.0
AnyWithProps (interface)
Section titled “AnyWithProps (interface)”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>}Since v4.0.0
DurableDeferred (interface)
Section titled “DurableDeferred (interface)”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>>}Since v4.0.0
racing
Section titled “racing”raceAll
Section titled “raceAll”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>Since v4.0.0
Schema for branded durable deferred tokens.
Signature
declare const Token: Schema.brand<Schema.String, "~effect/workflow/DurableDeferred/Token">Since v4.0.0
Token (type alias)
Section titled “Token (type alias)”Branded string token identifying a durable deferred for a workflow execution.
Signature
type Token = Brand.Branded<string, TokenTypeId>Since v4.0.0
TokenParsed (class)
Section titled “TokenParsed (class)”Schema for a decoded durable deferred token containing the workflow name, execution ID, and deferred name.
Signature
declare class TokenParsedSince 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>Since v4.0.0
tokenFromExecutionId
Section titled “tokenFromExecutionId”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}Since v4.0.0
tokenFromPayload
Section titled “tokenFromPayload”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>}Since v4.0.0
type IDs
Section titled “type IDs”TokenTypeId
Section titled “TokenTypeId”Runtime brand identifier for durable deferred tokens.
Signature
declare const TokenTypeId: "~effect/workflow/DurableDeferred/Token"Since v4.0.0
TokenTypeId (type alias)
Section titled “TokenTypeId (type alias)”Type-level brand identifier for Token values.
Signature
type TokenTypeId = typeof TokenTypeIdSince v4.0.0