<Eff extends Effect<any, any, any>>(
all: Iterable<Eff>,
options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>
readonly index: number
readonly parentFiber: Fiber<any, any>
}) => void
}
): Effect<Success<Eff>, Error<Eff>, Services<Eff>>Runs multiple effects concurrently and returns the first successful result.
When to use
Use when early failures should be ignored until a success occurs or all effects fail.
Details
Early failures do not finish the race; raceAll keeps waiting until one
effect succeeds or every effect has failed. When one effect succeeds, the
remaining effects are interrupted. If every effect fails, the returned effect
fails with a cause containing the collected failure reasons.
Example (Racing many effects)
import { Duration, Effect } from "effect"
// Multiple effects with different delays
const effect1 = Effect.delay(Effect.succeed("Fast"), Duration.millis(100))
const effect2 = Effect.delay(Effect.succeed("Slow"), Duration.millis(500))
const effect3 = Effect.delay(Effect.succeed("Very Slow"), Duration.millis(1000))
// Race all effects - the first to succeed wins
const raced = Effect.raceAll([effect1, effect2, effect3])
// Result: "Fast" (after ~100ms)export const const raceAll: <
Eff extends Effect<any, any, any>
>(
all: Iterable<Eff>,
options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>
readonly index: number
readonly parentFiber: Fiber<any, any>
}) => void
}
) => Effect<
Success<Eff>,
Error<Eff>,
Services<Eff>
>
Runs multiple effects concurrently and returns the first successful result.
When to use
Use when early failures should be ignored until a success occurs
or all effects fail.
Details
Early failures do not finish the race; raceAll keeps waiting until one
effect succeeds or every effect has failed. When one effect succeeds, the
remaining effects are interrupted. If every effect fails, the returned effect
fails with a cause containing the collected failure reasons.
Example (Racing many effects)
import { Duration, Effect } from "effect"
// Multiple effects with different delays
const effect1 = Effect.delay(Effect.succeed("Fast"), Duration.millis(100))
const effect2 = Effect.delay(Effect.succeed("Slow"), Duration.millis(500))
const effect3 = Effect.delay(Effect.succeed("Very Slow"), Duration.millis(1000))
// Race all effects - the first to succeed wins
const raced = Effect.raceAll([effect1, effect2, effect3])
// Result: "Fast" (after ~100ms)
raceAll: <function (type parameter) Eff in <Eff extends Effect<any, any, any>>(all: Iterable<Eff>, options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>;
readonly index: number;
readonly parentFiber: Fiber<any, any>;
}) => void;
}): Effect<Success<Eff>, Error<Eff>, Services<Eff>>
Eff extends 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<any, any, any>>(
all: Iterable<Eff>all: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) Eff in <Eff extends Effect<any, any, any>>(all: Iterable<Eff>, options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>;
readonly index: number;
readonly parentFiber: Fiber<any, any>;
}) => void;
}): Effect<Success<Eff>, Error<Eff>, Services<Eff>>
Eff>,
options: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>
readonly index: number
readonly parentFiber: Fiber<any, any>
}) => void
}
options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>
readonly index: number
readonly parentFiber: Fiber<any, any>
}) => void
onWinner?: (options: {
readonly fiber: Fiber<any, any>
readonly index: number
readonly parentFiber: Fiber<any, any>
}
options: {
readonly fiber: Fiber<any, any>(property) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
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; <…;
}
fiber: interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<any, any>
readonly index: numberindex: number
readonly parentFiber: Fiber<any, any>(property) parentFiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
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; <…;
}
parentFiber: interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<any, any>
}) => void
}
) => 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<type Success<T> = T extends Effect<
infer _A,
infer _E,
infer _R
>
? _A
: never
Extracts the success type from an Effect.
When to use
Use to derive the value produced by an existing effect when declaring
reusable type aliases, service interfaces, or function signatures.
Success<function (type parameter) Eff in <Eff extends Effect<any, any, any>>(all: Iterable<Eff>, options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>;
readonly index: number;
readonly parentFiber: Fiber<any, any>;
}) => void;
}): Effect<Success<Eff>, Error<Eff>, Services<Eff>>
Eff>, type Error<T> = T extends Effect<
infer _A,
infer _E,
infer _R
>
? _E
: never
Extracts the error type from an Effect.
When to use
Use to derive the error type from an existing Effect type when declaring
helper types, wrappers, or APIs that preserve the effect's failure channel.
Details
Non-Effect inputs resolve to never.
Error<function (type parameter) Eff in <Eff extends Effect<any, any, any>>(all: Iterable<Eff>, options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>;
readonly index: number;
readonly parentFiber: Fiber<any, any>;
}) => void;
}): Effect<Success<Eff>, Error<Eff>, Services<Eff>>
Eff>, type Services<T> = T extends Effect<
infer _A,
infer _E,
infer _R
>
? _R
: never
Extracts the required services type from an Effect.
When to use
Use to derive the context requirements of a generic or inferred Effect
without restating its R type parameter.
Services<function (type parameter) Eff in <Eff extends Effect<any, any, any>>(all: Iterable<Eff>, options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber<any, any>;
readonly index: number;
readonly parentFiber: Fiber<any, any>;
}) => void;
}): Effect<Success<Eff>, Error<Eff>, Services<Eff>>
Eff>> = import internalinternal.const raceAll: <
Eff extends Effect.Effect<any, any, any>
>(
all: Iterable<Eff>,
options?: {
readonly onWinner?: (options: {
readonly fiber: Fiber.Fiber<any, any>
readonly index: number
readonly parentFiber: Fiber.Fiber<any, any>
}) => void
}
) => Effect.Effect<
Effect.Success<Eff>,
Effect.Error<Eff>,
Effect.Services<Eff>
>
raceAll