<Input, Output, EnvX, Error, ErrorX, Env>(
step: Effect<
(
now: number,
input: Input
) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>,
Error,
Env
>
): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Creates a Schedule from a step function that returns a Pull.
Example (Creating a custom schedule from a step function)
import { Cause, Duration, Effect, Schedule } from "effect"
const schedule = Schedule.fromStep(Effect.sync(() => {
let count = 0
return (_now: number, _input: string) => {
if (count >= 3) {
return Cause.done(count)
}
return Effect.succeed([count++, Duration.millis(100)] as [number, Duration.Duration])
}
}))constructors
Source effect/Schedule.ts:28311 lines
export const const fromStep: <
Input,
Output,
EnvX,
Error,
ErrorX,
Env
>(
step: Effect<
(
now: number,
input: Input
) => Pull.Pull<
[Output, Duration.Duration],
ErrorX,
Output,
EnvX
>,
Error,
Env
>
) => Schedule<
Output,
Input,
Error | Pull.ExcludeDone<ErrorX>,
Env | EnvX
>
Creates a Schedule from a step function that returns a Pull.
Example (Creating a custom schedule from a step function)
import { Cause, Duration, Effect, Schedule } from "effect"
const schedule = Schedule.fromStep(Effect.sync(() => {
let count = 0
return (_now: number, _input: string) => {
if (count >= 3) {
return Cause.done(count)
}
return Effect.succeed([count++, Duration.millis(100)] as [number, Duration.Duration])
}
}))
fromStep = <function (type parameter) Input in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Input, function (type parameter) Output in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Output, function (type parameter) EnvX in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>EnvX, function (type parameter) Error in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Error, function (type parameter) ErrorX in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>ErrorX, function (type parameter) Env in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Env>(
step: Effect<
(
now: number,
input: Input
) => Pull.Pull<
[Output, Duration.Duration],
ErrorX,
Output,
EnvX
>,
Error,
Env
>
(parameter) step: {
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;
}
step: import EffectEffect<
(now: numbernow: number, input: Inputinput: function (type parameter) Input in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Input) => import PullPull.type Pull.Pull = /*unresolved*/ anyPull<[function (type parameter) Output in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Output, import DurationDuration.type Duration.Duration = /*unresolved*/ anyDuration], function (type parameter) ErrorX in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>ErrorX, function (type parameter) Output in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Output, function (type parameter) EnvX in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>EnvX>,
function (type parameter) Error in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Error,
function (type parameter) Env in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Env
>
): 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 <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Output, function (type parameter) Input in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Input, function (type parameter) Error in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Error | import PullPull.type Pull.ExcludeDone = /*unresolved*/ anyExcludeDone<function (type parameter) ErrorX in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>ErrorX>, function (type parameter) Env in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>Env | function (type parameter) EnvX in <Input, Output, EnvX, Error, ErrorX, Env>(step: Effect<(now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>EnvX> => {
const const self: anyself = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const ScheduleProto: {
"~effect/Schedule": {
_Out: any
_In: any
_Env: any
}
pipe(): any
}
ScheduleProto)
const self: anyself.step = step: Effect<
(
now: number,
input: Input
) => Pull.Pull<
[Output, Duration.Duration],
ErrorX,
Output,
EnvX
>,
Error,
Env
>
(parameter) step: {
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;
}
step
return const self: anyself
}Referenced by 10 symbols