anyType helpers for retrying effects.
export declare namespace Retry {
/**
* Computes the result type of `Effect.retry` from the original effect and retry options.
*
* @category error handling
* @since 2.0.0
*/
export type type Retry.Return<R, E, A, O extends Retry.Options<E>> = Effect<A, (O extends {
schedule: Schedule<infer _O, infer _I, infer _E1, infer _R>;
} ? E : O extends {
times: number;
} ? E : O extends {
until: Predicate.Refinement<E, infer E2>;
} ? E2 : O extends {
while: Predicate.Refinement<E, infer E2>;
} ? Exclude<E, E2> : E) | (O extends {
schedule: Schedule<infer _O, infer _I, infer E, infer _R>;
} ? E : never) | (O extends {
while: (...args: Array<any>) => Effect<infer _A, infer E, infer _R>;
} ? E : never) | (O extends {
...;
} ? E : never), R | ... 2 more ... | (O extends {
...;
} ? R : never)>
Computes the result type of Effect.retry from the original effect and retry options.
Return<function (type parameter) R in type Retry.Return<R, E, A, O extends Retry.Options<E>>R, function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E, function (type parameter) A in type Retry.Return<R, E, A, O extends Retry.Options<E>>A, function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends interface Retry.Options<E>Options that control whether and how a failing effect is retried.
Options<function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E>> = interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
function (type parameter) A in type Retry.Return<R, E, A, O extends Retry.Options<E>>A,
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { schedule: Schedule<
infer _O,
infer _I,
infer _E1,
infer _R
>
(property) 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<infer function (type parameter) _O_O, infer function (type parameter) _I_I, infer function (type parameter) _E1_E1, infer function (type parameter) _R_R> } ? function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E
: function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { times: numbertimes: number } ? function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E
: function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { until: Predicate.Refinement<E, infer E2>until: import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E, infer function (type parameter) E2E2> } ? function (type parameter) E2E2
: function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { while: Predicate.Refinement<E, infer E2>while: import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E, infer function (type parameter) E2E2> } ? type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E, function (type parameter) E2E2>
: function (type parameter) E in type Retry.Return<R, E, A, O extends Retry.Options<E>>E)
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { schedule: Schedule<
infer _O,
infer _I,
infer E,
infer _R
>
(property) 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<infer function (type parameter) _O_O, infer function (type parameter) _I_I, infer function (type parameter) EE, infer function (type parameter) _R_R> } ? function (type parameter) EE
: never)
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { while: (
...args: Array<any>
) => Effect<infer _A, infer E, infer _R>
while: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) EE, infer function (type parameter) _R_R> } ? function (type parameter) EE
: never)
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { until: (
...args: Array<any>
) => Effect<infer _A, infer E, infer _R>
until: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) EE, infer function (type parameter) _R_R> } ? function (type parameter) EE
: never),
| function (type parameter) R in type Retry.Return<R, E, A, O extends Retry.Options<E>>R
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { schedule: Schedule<
infer _O,
infer _I,
infer _E1,
infer R
>
(property) 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<infer function (type parameter) _O_O, infer function (type parameter) _I_I, infer function (type parameter) _E1_E1, infer function (type parameter) RR> } ? function (type parameter) RR
: never)
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { while: (
...args: Array<any>
) => Effect<infer _A, infer _E, infer R>
while: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) RR> } ? function (type parameter) RR
: never)
| (function (type parameter) O in type Retry.Return<R, E, A, O extends Retry.Options<E>>O extends { until: (
...args: Array<any>
) => Effect<infer _A, infer _E, infer R>
until: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) RR> } ? function (type parameter) RR
: never)
> extends infer function (type parameter) ZZ ? function (type parameter) ZZ
: never
/**
* Options that control whether and how a failing effect is retried.
*
* @category error handling
* @since 2.0.0
*/
export interface interface Retry.Options<E>Options that control whether and how a failing effect is retried.
Options<function (type parameter) E in Options<E>E> {
Retry.Options<E>.while?: ((error: E) => boolean | Effect<boolean, any, any>) | undefinedwhile?: ((error: Eerror: function (type parameter) E in Options<E>E) => boolean | interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean, any, any>) | undefined
Retry.Options<E>.until?: ((error: E) => boolean | Effect<boolean, any, any>) | undefineduntil?: ((error: Eerror: function (type parameter) E in Options<E>E) => boolean | interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean, any, any>) | undefined
Retry.Options<E>.times?: number | undefinedtimes?: number | undefined
Retry.Options<E>.schedule?: Schedule<any, E, any, any> | undefinedschedule?: 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<any, function (type parameter) E in Options<E>E, any, any> | undefined
}
}