Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

ExecutionPlan

8 exports Since v3.16.0 Source

Combining

Since v3.16.0

Signature

declare function merge<Plans extends readonly [ExecutionPlan<any>, ExecutionPlan<any>]>(...plans: Plans): ExecutionPlan<{
error: Plans[number] extends ExecutionPlan<T> ? T["error"] : never;
input: PlanInput<Plans>;
provides: PlanProvides<Plans>;
requirements: Plans[number] extends ExecutionPlan<T> ? T["requirements"] : never;
}>

Constructors

Since v3.16.0

Create an ExecutionPlan, which can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.

Signature

declare function make<Steps extends readonly [Step, Step]>(...steps: Steps & { [K in string | number | symbol]: Step }): ExecutionPlan<{
error: Steps[number]["provide"] extends Context<_P> | Layer<_P, E, _R> ? E : never | Steps[number]["while"] extends (input: _I) => Effect<_A, _E, _R> ? _E : never;
input: StepInput<Steps>;
provides: StepProvides<Steps>;
requirements: Steps[number]["provide"] extends Layer<_A, _E, R> ? R : never | Steps[number]["while"] extends (input: _I) => Effect<_A, _E, R> ? R : never | Steps[number]["schedule"] extends Schedule<_O, _I, R> ? R : never;
}>

Example

import type { LanguageModel } from "@effect/ai"
import type { Layer } from "effect"
import { Effect, ExecutionPlan, Schedule } from "effect"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)

Guards

Signature

declare const isExecutionPlan: (u: unknown) => u is ExecutionPlan<any>

Models

ExecutionPlan

interface
Since v3.16.0

A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.

Signature

interface ExecutionPlan<Types extends {
error: any;
input: any;
provides: any;
requirements: any;
}> extends Pipeable {
readonly [TypeId]: typeof TypeId;
readonly steps: readonly [{
readonly attempts?: number;
readonly provide: Context<Types["provides"]> | Layer<Types["provides"], Types["error"], Types["requirements"]>;
readonly schedule?: Schedule<any, Types["input"], Types["requirements"]>;
readonly while?: (input: Types["input"]) => Effect<boolean, Types["error"], Types["requirements"]>;
}, {
readonly attempts?: number;
readonly provide: Context<Types["provides"]> | Layer<Types["provides"], Types["error"], Types["requirements"]>;
readonly schedule?: Schedule<any, Types["input"], Types["requirements"]>;
readonly while?: (input: Types["input"]) => Effect<boolean, Types["error"], Types["requirements"]>;
}];
readonly withRequirements: Effect<ExecutionPlan<{
error: Types["error"];
input: Types["input"];
provides: Types["provides"];
requirements: never;
}>, never, Types["requirements"]>;
}

Example

import type { LanguageModel } from "@effect/ai"
import type { Layer } from "effect"
import { Effect, ExecutionPlan, Schedule } from "effect"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)

Other

Since v3.16.0
Since v3.16.0

Signature

type TypesBase = {
error: any;
input: any;
provides: any;
requirements: any;
}

Symbols

Since v3.16.0

Signature

declare const TypeId: unique symbol
Since v3.16.0

Signature

type TypeId = typeof TypeId