<Output, Input, Error, Env>(
self: Schedule<Output, Input, Error, Env>
): Schedule<Input, Input, Error, Env>Returns a new Schedule that outputs the inputs of the specified schedule.
Example (Passing inputs through as outputs)
import { Console, Effect, Schedule } from "effect"
// Create a schedule that outputs the inputs instead of original outputs
const inputSchedule = Schedule.passthrough(
Schedule.exponential("100 millis").pipe(Schedule.upTo({ times: 3 }))
)
const program = Effect.gen(function*() {
let counter = 0
yield* Effect.repeat(
Effect.gen(function*() {
counter++
yield* Console.log(`Task ${counter} executed`)
return `result-${counter}`
}),
inputSchedule
)
})export const const passthrough: <
Output,
Input,
Error,
Env
>(
self: Schedule<Output, Input, Error, Env>
) => Schedule<Input, Input, Error, Env>
Returns a new Schedule that outputs the inputs of the specified schedule.
Example (Passing inputs through as outputs)
import { Console, Effect, Schedule } from "effect"
// Create a schedule that outputs the inputs instead of original outputs
const inputSchedule = Schedule.passthrough(
Schedule.exponential("100 millis").pipe(Schedule.upTo({ times: 3 }))
)
const program = Effect.gen(function*() {
let counter = 0
yield* Effect.repeat(
Effect.gen(function*() {
counter++
yield* Console.log(`Task ${counter} executed`)
return `result-${counter}`
}),
inputSchedule
)
})
passthrough = <function (type parameter) Output in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Output, function (type parameter) Input in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Input, function (type parameter) Error in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Error, function (type parameter) Env in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Env>(
self: Schedule<Output, Input, Error, Env>(parameter) self: {
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; <…;
}
self: 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>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Output, function (type parameter) Input in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Input, function (type parameter) Error in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Error, function (type parameter) Env in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>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) Input in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Input, function (type parameter) Input in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Input, function (type parameter) Error in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Error, function (type parameter) Env in <Output, Input, Error, Env>(self: Schedule<Output, Input, Error, Env>): Schedule<Input, Input, Error, Env>Env> =>
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(import effecteffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E, R>
<A, E, R, B>(
self: Effect.Effect<A, E, R>,
f: (a: A) => B
): Effect.Effect<B, E, R>
}
map(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(self: Schedule<Output, Input, Error, Env>(parameter) self: {
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; <…;
}
self), (step: unknownstep) => (now: anynow, input: anyinput) =>
import PullPull.matchEffect(step: unknownstep(now: anynow, input: anyinput), {
onSuccess: (result: any) => Effect.Effect<A>onSuccess: (result: any(parameter) result: {
0: Output;
1: Duration.Duration;
length: 2;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Duration.Duration | Output | undefined;
push: (...items: Array<Duration.Duration | Output>) => number;
concat: { (...items: Array<ConcatArray<Duration.Duration | Output>>): Array<Duration.Duration | Output>; (...items: Array<Duration.Duration | Output | ConcatArray<Duration.Duration | Output>>): Array<Duration.Duration | Output> };
join: (separator?: string) => string;
reverse: () => Array<Duration.Duration | Output>;
shift: () => Duration.Duration | Output | undefined;
slice: (start?: number, end?: number) => Array<Duration.Duration | Output>;
sort: (compareFn?: ((a: Duration.Duration | Output, b: Duration.Duration | Output) => number) | undefined) => [Output, Duration.Duration];
splice: { (start: number, deleteCount?: number): Array<Duration.Duration | Output>; (start: number, deleteCount: number, ...items: Array<Duration.Duration | Output>): Array<Duration.Duration | Output> };
unshift: (...items: Array<Duration.Duration | Output>) => number;
indexOf: (searchElement: Duration.Duration | Output, fromIndex?: number) => number;
lastIndexOf: (searchElement: Duration.Duration | Output, fromIndex?: number) => number;
every: { (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Dur…;
some: (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Durati…;
reduce: { (callbackfn: (previousValue: Duration.Duration | Output, currentValue: Duration.Duration | Output, currentIndex: number, array: Array<Duration.Duration | Output>) => Duration.Duration | Output): Duration.Duration | Output; (callbackfn: (…;
reduceRight: { (callbackfn: (previousValue: Duration.Duration | Output, currentValue: Duration.Duration | Output, currentIndex: number, array: Array<Duration.Duration | Output>) => Duration.Duration | Output): Duration.Duration | Output; (callbackfn: (…;
find: { (predicate: (value: Duration.Duration | Output, index: number, obj: Array<Duration.Duration | Output>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Duration.Duration | Output, index: number, obj: Array<Duration.Durat…;
findIndex: (predicate: (value: Duration.Duration | Output, index: number, obj: Array<Duration.Duration | Output>) => unknown, thisArg?: any) => number;
fill: (value: Duration.Duration | Output, start?: number, end?: number) => [Output, Duration.Duration];
copyWithin: (target: number, start: number, end?: number) => [Output, Duration.Duration];
entries: () => ArrayIterator<[number, Duration.Duration | Output]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Duration.Duration | Output>;
includes: (searchElement: Duration.Duration | Output, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Duration.Duration | Output | undefined;
findLast: { (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.D…;
findLastIndex: (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Duration.Duration | Output>;
toSorted: (compareFn?: ((a: Duration.Duration | Output, b: Duration.Duration | Output) => number) | undefined) => Array<Duration.Duration | Output>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Duration.Duration | Output>): Array<Duration.Duration | Output>; (start: number, deleteCount?: number): Array<Duration.Duration | Output> };
with: (index: number, value: Duration.Duration | Output) => Array<Duration.Duration | Output>;
}
result) => import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed([input: anyinput, result: any(parameter) result: {
0: Output;
1: Duration.Duration;
length: 2;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Duration.Duration | Output | undefined;
push: (...items: Array<Duration.Duration | Output>) => number;
concat: { (...items: Array<ConcatArray<Duration.Duration | Output>>): Array<Duration.Duration | Output>; (...items: Array<Duration.Duration | Output | ConcatArray<Duration.Duration | Output>>): Array<Duration.Duration | Output> };
join: (separator?: string) => string;
reverse: () => Array<Duration.Duration | Output>;
shift: () => Duration.Duration | Output | undefined;
slice: (start?: number, end?: number) => Array<Duration.Duration | Output>;
sort: (compareFn?: ((a: Duration.Duration | Output, b: Duration.Duration | Output) => number) | undefined) => [Output, Duration.Duration];
splice: { (start: number, deleteCount?: number): Array<Duration.Duration | Output>; (start: number, deleteCount: number, ...items: Array<Duration.Duration | Output>): Array<Duration.Duration | Output> };
unshift: (...items: Array<Duration.Duration | Output>) => number;
indexOf: (searchElement: Duration.Duration | Output, fromIndex?: number) => number;
lastIndexOf: (searchElement: Duration.Duration | Output, fromIndex?: number) => number;
every: { (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Dur…;
some: (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Durati…;
reduce: { (callbackfn: (previousValue: Duration.Duration | Output, currentValue: Duration.Duration | Output, currentIndex: number, array: Array<Duration.Duration | Output>) => Duration.Duration | Output): Duration.Duration | Output; (callbackfn: (…;
reduceRight: { (callbackfn: (previousValue: Duration.Duration | Output, currentValue: Duration.Duration | Output, currentIndex: number, array: Array<Duration.Duration | Output>) => Duration.Duration | Output): Duration.Duration | Output; (callbackfn: (…;
find: { (predicate: (value: Duration.Duration | Output, index: number, obj: Array<Duration.Duration | Output>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Duration.Duration | Output, index: number, obj: Array<Duration.Durat…;
findIndex: (predicate: (value: Duration.Duration | Output, index: number, obj: Array<Duration.Duration | Output>) => unknown, thisArg?: any) => number;
fill: (value: Duration.Duration | Output, start?: number, end?: number) => [Output, Duration.Duration];
copyWithin: (target: number, start: number, end?: number) => [Output, Duration.Duration];
entries: () => ArrayIterator<[number, Duration.Duration | Output]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Duration.Duration | Output>;
includes: (searchElement: Duration.Duration | Output, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Duration.Duration | Output | undefined;
findLast: { (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.D…;
findLastIndex: (predicate: (value: Duration.Duration | Output, index: number, array: Array<Duration.Duration | Output>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Duration.Duration | Output>;
toSorted: (compareFn?: ((a: Duration.Duration | Output, b: Duration.Duration | Output) => number) | undefined) => Array<Duration.Duration | Output>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Duration.Duration | Output>): Array<Duration.Duration | Output>; (start: number, deleteCount?: number): Array<Duration.Duration | Output> };
with: (index: number, value: Duration.Duration | Output) => Array<Duration.Duration | Output>;
}
result[1]]),
onFailure: <E>(
cause: Cause.Cause<E>
) => Effect.Effect<never, E>
onFailure: import effecteffect.const failCause: <E>(
cause: Cause.Cause<E>
) => Effect.Effect<never, E>
failCause,
onDone: () => anyonDone: () => import CauseCause.done(input: anyinput)
})))