<Output, Input, Error, Env>(
schedule: Schedule<Output, Input, Error, Env>
): Effect<
(
now: number,
input: Input
) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>,
never,
Env
>Extracts the step function from a Schedule.
Example (Extracting a schedule step function)
import { Effect, Schedule } from "effect"
// Extract step function from an existing schedule
const schedule = Schedule.exponential("100 millis").pipe(Schedule.upTo({ times: 3 }))
const program = Effect.gen(function*() {
const stepFn = yield* Schedule.toStep(schedule)
// Use the step function directly for custom logic. The timestamp is
// supplied by the caller, so tests can pass a deterministic value.
const now = 0
const result = yield* stepFn(now, "input")
console.log(`Step result: ${result}`)
})destructors
Source effect/Schedule.ts:36911 lines
export const const toStep: <Output, Input, Error, Env>(
schedule: Schedule<Output, Input, Error, Env>
) => Effect<
(
now: number,
input: Input
) => Pull.Pull<
[Output, Duration.Duration],
Error,
Output,
Env
>,
never,
Env
>
Extracts the step function from a Schedule.
Example (Extracting a schedule step function)
import { Effect, Schedule } from "effect"
// Extract step function from an existing schedule
const schedule = Schedule.exponential("100 millis").pipe(Schedule.upTo({ times: 3 }))
const program = Effect.gen(function*() {
const stepFn = yield* Schedule.toStep(schedule)
// Use the step function directly for custom logic. The timestamp is
// supplied by the caller, so tests can pass a deterministic value.
const now = 0
const result = yield* stepFn(now, "input")
console.log(`Step result: ${result}`)
})
toStep = <function (type parameter) Output in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Output, function (type parameter) Input in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Input, function (type parameter) Error in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Error, function (type parameter) Env in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Env>(
schedule: Schedule<Output, Input, Error, Env>(parameter) schedule: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schedule: interface Schedule<out Output, in Input = unknown, out Error = never, out Env = never>A Schedule defines a strategy for repeating or retrying effects based on some policy.
Example (Defining retry and repeat schedules)
import { Console, Data, Effect, Schedule } from "effect"
class NetworkError extends Data.TaggedError("NetworkError")<{
readonly attempt: number
}> {}
// Basic retry schedule - retry up to 3 times with exponential backoff
const retrySchedule = Schedule.max([
Schedule.exponential("100 millis"),
Schedule.recurs(3)
])
// Basic repeat schedule - repeat every 30 seconds forever
const repeatSchedule: Schedule.Schedule<number, unknown, never> = Schedule
.spaced("30 seconds")
const program = Effect.gen(function*() {
let attempts = 0
const result1 = yield* Effect.retry(
Effect.gen(function*() {
attempts++
if (attempts < 3) {
return yield* Effect.fail(new NetworkError({ attempt: attempts }))
}
return "Success"
}),
retrySchedule
)
console.log(result1) // "Success"
yield* Console.log("heartbeat").pipe(
Effect.repeat(repeatSchedule.pipe(Schedule.upTo({ times: 5 })))
)
})
The Schedule namespace contains types and utilities for working with schedules.
Schedule<function (type parameter) Output in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Output, function (type parameter) Input in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Input, function (type parameter) Error in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Error, function (type parameter) Env in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Env>
): import EffectEffect<
(now: numbernow: number, input: Inputinput: function (type parameter) Input in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Input) => import PullPull.type Pull.Pull = /*unresolved*/ anyPull<[function (type parameter) Output in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Output, import DurationDuration.type Duration.Duration = /*unresolved*/ anyDuration], function (type parameter) Error in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Error, function (type parameter) Output in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Output, function (type parameter) Env in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Env>,
never,
function (type parameter) Env in <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>): Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>, never, Env>Env
> =>
import effecteffect.const catchCause: {
<E, B, E2, R2>(
f: (
cause: NoInfer<Cause.Cause<E>>
) => Effect.Effect<B, E2, R2>
): <A, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A | B, E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: (
cause: NoInfer<Cause.Cause<E>>
) => Effect.Effect<B, E2, R2>
): Effect.Effect<A | B, E2, R | R2>
}
catchCause(
(schedule: Schedule<Output, Input, Error, Env>(parameter) schedule: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schedule as any).step,
(cause: Cause.Cause<unknown>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause) => import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(() => import effecteffect.const failCause: <E>(
cause: Cause.Cause<E>
) => Effect.Effect<never, E>
failCause(cause: Cause.Cause<unknown>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause) as any)
)Referenced by 8 symbols