<
const Arg extends
| Iterable<Effect<any, any, any>>
| Record<string, Effect<any, any, any>>,
O extends {
readonly concurrency?: Concurrency | undefined
readonly discard?: boolean | undefined
readonly mode?: "default" | "result" | undefined
}
>(
arg: Arg,
options?: O
): All.Return<Arg, O>Combines an iterable or record of effects into one effect whose success shape follows the input.
When to use
Use to run a known collection of effects and collect results in the same tuple, iterable, or record shape.
Details
Tuple and iterable inputs collect results in order. Record inputs collect results under the same keys. By default, the combined effect fails on the first failure; with concurrent execution, effects that have already started may be interrupted, while effects not yet started are skipped.
Options:
Use concurrency to control sequential or concurrent execution. Use
mode: "result" to run every effect and collect each success or failure as a
Result in the same output shape. Use discard: true to ignore successful
values and return void.
Example (Collecting tuple results in order)
import { Console, Effect } from "effect"
const tupleOfEffects = [
Effect.succeed(42).pipe(Effect.tap(Console.log)),
Effect.succeed("Hello").pipe(Effect.tap(Console.log))
] as const
// ┌─── Effect<[number, string], never, never>
// ▼
const resultsAsTuple = Effect.all(tupleOfEffects)
Effect.runPromise(resultsAsTuple).then(console.log)
// Output:
// 42
// Hello
// [ 42, 'Hello' ]Example (Collecting iterable results in order)
import { Console, Effect } from "effect"
const iterableOfEffects: Iterable<Effect.Effect<number>> = [1, 2, 3].map(
(n) => Effect.succeed(n).pipe(Effect.tap(Console.log))
)
// ┌─── Effect<number[], never, never>
// ▼
const resultsAsArray = Effect.all(iterableOfEffects)
Effect.runPromise(resultsAsArray).then(console.log)
// Output:
// 1
// 2
// 3
// [ 1, 2, 3 ]Example (Collecting struct results by key)
import { Console, Effect } from "effect"
const structOfEffects = {
a: Effect.succeed(42).pipe(Effect.tap(Console.log)),
b: Effect.succeed("Hello").pipe(Effect.tap(Console.log))
}
// ┌─── Effect<{ a: number; b: string; }, never, never>
// ▼
const resultsAsStruct = Effect.all(structOfEffects)
Effect.runPromise(resultsAsStruct).then(console.log)
// Output:
// 42
// Hello
// { a: 42, b: 'Hello' }Example (Collecting record results by key)
import { Console, Effect } from "effect"
const recordOfEffects: Record<string, Effect.Effect<number>> = {
key1: Effect.succeed(1).pipe(Effect.tap(Console.log)),
key2: Effect.succeed(2).pipe(Effect.tap(Console.log))
}
// ┌─── Effect<{ [x: string]: number; }, never, never>
// ▼
const resultsAsRecord = Effect.all(recordOfEffects)
Effect.runPromise(resultsAsRecord).then(console.log)
// Output:
// 1
// 2
// { key1: 1, key2: 2 }Example (Stopping on the first failure)
import { Console, Effect } from "effect"
const program = Effect.all([
Effect.succeed("Task1").pipe(Effect.tap(Console.log)),
Effect.fail("Task2: Oh no!").pipe(Effect.tap(Console.log)),
// Won't execute due to earlier failure
Effect.succeed("Task3").pipe(Effect.tap(Console.log))
])
Effect.runPromiseExit(program).then(console.log)
// Output:
// Task1
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: { _id: 'Cause', _tag: 'Fail', failure: 'Task2: Oh no!' }
// }export const const all: <
Arg extends
| Iterable<Effect<any, any, any>>
| Record<string, Effect<any, any, any>>,
O extends {
readonly concurrency?: Concurrency | undefined
readonly discard?: boolean | undefined
readonly mode?:
| "default"
| "result"
| undefined
}
>(
arg: Arg,
options?: O
) => All.Return<Arg, O>
Combines an iterable or record of effects into one effect whose success shape
follows the input.
When to use
Use to run a known collection of effects and collect results in the same
tuple, iterable, or record shape.
Details
Tuple and iterable inputs collect results in order. Record inputs collect
results under the same keys. By default, the combined effect fails on the
first failure; with concurrent execution, effects that have already started
may be interrupted, while effects not yet started are skipped.
Options:
Use concurrency to control sequential or concurrent execution. Use
mode: "result" to run every effect and collect each success or failure as a
Result in the same output shape. Use discard: true to ignore successful
values and return void.
Example (Collecting tuple results in order)
import { Console, Effect } from "effect"
const tupleOfEffects = [
Effect.succeed(42).pipe(Effect.tap(Console.log)),
Effect.succeed("Hello").pipe(Effect.tap(Console.log))
] as const
// ┌─── Effect<[number, string], never, never>
// ▼
const resultsAsTuple = Effect.all(tupleOfEffects)
Effect.runPromise(resultsAsTuple).then(console.log)
// Output:
// 42
// Hello
// [ 42, 'Hello' ]
Example (Collecting iterable results in order)
import { Console, Effect } from "effect"
const iterableOfEffects: Iterable<Effect.Effect<number>> = [1, 2, 3].map(
(n) => Effect.succeed(n).pipe(Effect.tap(Console.log))
)
// ┌─── Effect<number[], never, never>
// ▼
const resultsAsArray = Effect.all(iterableOfEffects)
Effect.runPromise(resultsAsArray).then(console.log)
// Output:
// 1
// 2
// 3
// [ 1, 2, 3 ]
Example (Collecting struct results by key)
import { Console, Effect } from "effect"
const structOfEffects = {
a: Effect.succeed(42).pipe(Effect.tap(Console.log)),
b: Effect.succeed("Hello").pipe(Effect.tap(Console.log))
}
// ┌─── Effect<{ a: number; b: string; }, never, never>
// ▼
const resultsAsStruct = Effect.all(structOfEffects)
Effect.runPromise(resultsAsStruct).then(console.log)
// Output:
// 42
// Hello
// { a: 42, b: 'Hello' }
Example (Collecting record results by key)
import { Console, Effect } from "effect"
const recordOfEffects: Record<string, Effect.Effect<number>> = {
key1: Effect.succeed(1).pipe(Effect.tap(Console.log)),
key2: Effect.succeed(2).pipe(Effect.tap(Console.log))
}
// ┌─── Effect<{ [x: string]: number; }, never, never>
// ▼
const resultsAsRecord = Effect.all(recordOfEffects)
Effect.runPromise(resultsAsRecord).then(console.log)
// Output:
// 1
// 2
// { key1: 1, key2: 2 }
Example (Stopping on the first failure)
import { Console, Effect } from "effect"
const program = Effect.all([
Effect.succeed("Task1").pipe(Effect.tap(Console.log)),
Effect.fail("Task2: Oh no!").pipe(Effect.tap(Console.log)),
// Won't execute due to earlier failure
Effect.succeed("Task3").pipe(Effect.tap(Console.log))
])
Effect.runPromiseExit(program).then(console.log)
// Output:
// Task1
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: { _id: 'Cause', _tag: 'Fail', failure: 'Task2: Oh no!' }
// }
all: <
const function (type parameter) Arg in <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>, O extends {
readonly concurrency?: Concurrency | undefined;
readonly discard?: boolean | undefined;
readonly mode?: "default" | "result" | undefined;
}>(arg: Arg, options?: O): All.Return<Arg, O>
Arg extends
| interface Iterable<T, TReturn = any, TNext = any>Iterable<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>>
| type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, 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>>,
function (type parameter) O in <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>, O extends {
readonly concurrency?: Concurrency | undefined;
readonly discard?: boolean | undefined;
readonly mode?: "default" | "result" | undefined;
}>(arg: Arg, options?: O): All.Return<Arg, O>
O extends {
readonly concurrency?: Concurrency | undefinedconcurrency?: type Concurrency = number | "unbounded" | "inherit"Describes the concurrency level for Effect operations that run multiple
effects.
When to use
Use to type options that control how many effects may run at the same time.
Details
number — run at most N effects concurrently.
"unbounded" — run all effects concurrently with no limit.
"inherit" — inherit the concurrency from the surrounding context.
Example (Setting concurrency values)
import type { Types } from "effect"
const sequential: Types.Concurrency = 1
const limited: Types.Concurrency = 5
const unbounded: Types.Concurrency = "unbounded"
const inherit: Types.Concurrency = "inherit"
Concurrency | undefined
readonly discard?: boolean | undefineddiscard?: boolean | undefined
readonly mode?: "result" | "default" | undefinedmode?: "default" | "result" | undefined
}
>(
arg: const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>arg: function (type parameter) Arg in <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>, O extends {
readonly concurrency?: Concurrency | undefined;
readonly discard?: boolean | undefined;
readonly mode?: "default" | "result" | undefined;
}>(arg: Arg, options?: O): All.Return<Arg, O>
Arg,
options: O | undefinedoptions?: function (type parameter) O in <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>, O extends {
readonly concurrency?: Concurrency | undefined;
readonly discard?: boolean | undefined;
readonly mode?: "default" | "result" | undefined;
}>(arg: Arg, options?: O): All.Return<Arg, O>
O
) => All.type All.Return<Arg extends Iterable<All.EffectAny> | Record<string, All.EffectAny>, O extends { readonly concurrency?: Concurrency | undefined; readonly discard?: boolean | undefined; readonly mode?: "default" | "result" | undefined; }> = [Arg] extends [readonly All.EffectAny[]] ? Effect<All.IsDiscard<O> extends true ? void : Arg[number] extends never ? [] : { -readonly [K in keyof Arg]: Arg[K] extends Effect<infer _A, infer _E, infer _R> ? All.IsResult<O> extends true ? Result.Result<_A, _E> : _A : never; }, All.IsResult<O> extends true ? never : Arg[number] extends never ? never : Arg[number] extends Effect<infer _A, infer _E, infer _R> ? _E : never, Arg[number] extends never ? never : Arg[number] extends Effect<...> ? _R : never> : [...] extends [...] ? All.ReturnIterable<...> : [...] extends [...] ? All.ReturnObject<...> : neverComputes the return type for Effect.all from its input and options.
Return<function (type parameter) Arg in <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>, O extends {
readonly concurrency?: Concurrency | undefined;
readonly discard?: boolean | undefined;
readonly mode?: "default" | "result" | undefined;
}>(arg: Arg, options?: O): All.Return<Arg, O>
Arg, function (type parameter) O in <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>, O extends {
readonly concurrency?: Concurrency | undefined;
readonly discard?: boolean | undefined;
readonly mode?: "default" | "result" | undefined;
}>(arg: Arg, options?: O): All.Return<Arg, O>
O> = import internalinternal.const all: <
Arg extends
| Iterable<Effect.Effect<any, any, any>>
| Record<
string,
Effect.Effect<any, any, any>
>,
O extends {
readonly concurrency?: Concurrency | undefined
readonly discard?: boolean | undefined
readonly mode?:
| "default"
| "result"
| undefined
}
>(
arg: Arg,
options?: O
) => Effect.All.Return<Arg, O>
all