<A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?:
| (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined
})
| undefined
) => Promise<XA>,
never,
R
>Captures a Runtime and returns a Promise-based runner that forks effects
into the FiberSet.
When to use
Use when you need to bridge effects to Promise values while still tracking
their fibers in a FiberSet.
Details
The returned run function returns a Promise for each effect result.
Example (Running effects as promises)
import { Effect, FiberSet } from "effect"
const program = Effect.gen(function*() {
const set = yield* FiberSet.make()
const runPromise = yield* FiberSet.runtimePromise(set)()
// Run effects as promises
const promise1 = runPromise(Effect.succeed("hello"))
const promise2 = runPromise(Effect.succeed("world"))
const result1 = yield* Effect.promise(() => promise1)
const result2 = yield* Effect.promise(() => promise2)
console.log(result1, result2) // "hello" "world"
})export const const runtimePromise: <A, E>(
self: FiberSet<A, E>
) => <R = never>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?:
| (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
) => Promise<XA>,
never,
R
>
Captures a Runtime and returns a Promise-based runner that forks effects
into the FiberSet.
When to use
Use when you need to bridge effects to Promise values while still tracking
their fibers in a FiberSet.
Details
The returned run function returns a Promise for each effect result.
Example (Running effects as promises)
import { Effect, FiberSet } from "effect"
const program = Effect.gen(function*() {
const set = yield* FiberSet.make()
const runPromise = yield* FiberSet.runtimePromise(set)()
// Run effects as promises
const promise1 = runPromise(Effect.succeed("hello"))
const promise2 = runPromise(Effect.succeed("world"))
const result1 = yield* Effect.promise(() => promise1)
const result2 = yield* Effect.promise(() => promise2)
console.log(result1, result2) // "hello" "world"
})
runtimePromise = <function (type parameter) A in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
A, function (type parameter) E in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
E>(self: FiberSet<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: Set<Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
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;
}
self: interface FiberSet<out A = unknown, out E = unknown>A FiberSet is a collection of fibers that can be managed together.
When the associated Scope is closed, all fibers in the set will be interrupted.
Example (Managing fibers in a set)
import { Effect, FiberSet } from "effect"
const program = Effect.gen(function*() {
const set = yield* FiberSet.make<string, string>()
// Add fibers to the set
yield* FiberSet.run(set, Effect.succeed("hello"))
yield* FiberSet.run(set, Effect.succeed("world"))
// Wait for all fibers to complete
yield* FiberSet.awaitEmpty(set)
})
FiberSet<function (type parameter) A in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
A, function (type parameter) E in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
E>): <function (type parameter) R in <R = never>(): Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
R = never>() => import EffectEffect.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) XE in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XE extends function (type parameter) E in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
E, function (type parameter) XA in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XA extends function (type parameter) A in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
A>(
effect: Effect.Effect<XA, XE, R>(parameter) effect: {
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;
}
effect: import EffectEffect.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) XA in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XA, function (type parameter) XE in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XE, function (type parameter) R in <R = never>(): Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
R>,
options: | (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
options?:
| import EffectEffect.RunOptions & { readonly propagateInterruption?: boolean | undefinedpropagateInterruption?: boolean | undefined }
| undefined
) => interface Promise<T>Represents the completion of an asynchronous operation
Promise<function (type parameter) XA in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XA>,
never,
function (type parameter) R in <R = never>(): Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
R
> =>
<function (type parameter) R in <R>(): Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
R>() =>
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(
const runtime: <A, E>(
self: FiberSet<A, E>
) => <R = never>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?:
| (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
) => Fiber.Fiber<XA, XE>,
never,
R
>
Captures a Runtime and uses it to fork effects into the FiberSet.
Example (Capturing a runtime)
import { Context, Effect, FiberSet } from "effect"
interface Users {
readonly _: unique symbol
}
const Users = Context.Service<Users, {
getAll: Effect.Effect<Array<unknown>>
}>("Users")
Effect.gen(function*() {
const set = yield* FiberSet.make()
const run = yield* FiberSet.runtime(set)<Users>()
// run some effects and add the fibers to the set
run(Effect.andThen(Users, (_) => _.getAll))
}).pipe(
Effect.scoped // The fibers will be interrupted when the scope is closed
)
runtime(self: FiberSet<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: Set<Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
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;
}
self)<function (type parameter) R in <R>(): Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
R>(),
(runFork: (
effect: Effect.Effect<XA, XE, R>,
options?:
| (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
) => Fiber.Fiber<XA, XE>
runFork) =>
<function (type parameter) XE in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XE extends function (type parameter) E in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
E, function (type parameter) XA in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XA extends function (type parameter) A in <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
A>(
effect: Effect.Effect<XA, XE, R>(parameter) effect: {
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;
}
effect: import EffectEffect.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) XA in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XA, function (type parameter) XE in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XE, function (type parameter) R in <R>(): Effect.Effect<(<XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined) => Promise<XA>), never, R>
R>,
options: | (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
options?:
| import EffectEffect.RunOptions & { readonly propagateInterruption?: boolean | undefinedpropagateInterruption?: boolean | undefined }
| undefined
): interface Promise<T>Represents the completion of an asynchronous operation
Promise<function (type parameter) XA in <XE extends E, XA extends A>(effect: Effect.Effect<XA, XE, R>, options?: (Effect.RunOptions & {
readonly propagateInterruption?: boolean | undefined;
}) | undefined): Promise<XA>
XA> =>
new var Promise: PromiseConstructor
new <XA>(executor: (resolve: (value: XA | PromiseLike<XA>) => void, reject: (reason?: any) => void) => void) => Promise<XA>
Creates a new Promise.
Promise((resolve: (value: XA | PromiseLike<XA>) => voidresolve, reject: (reason?: any) => voidreject) =>
runFork: (
effect: Effect.Effect<XA, XE, R>,
options?:
| (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
) => Fiber.Fiber<XA, XE>
runFork(effect: Effect.Effect<XA, XE, R>(parameter) effect: {
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;
}
effect, options: | (Effect.RunOptions & {
readonly propagateInterruption?:
| boolean
| undefined
})
| undefined
options).Fiber<XA, XE>.addObserver: (cb: (exit: Exit<A, E>) => void) => () => voidaddObserver((exit: Exit.Exit<XA, XE>exit) => {
if (import ExitExit.const isSuccess: <A, E>(
self: Exit<A, E>
) => self is Success<A, E>
Checks whether an Exit is a Success.
When to use
Use as a type guard to narrow Exit<A, E> to Success<A, E> and access the
value property.
Example (Narrowing to success)
import { Exit } from "effect"
const exit = Exit.succeed(42)
if (Exit.isSuccess(exit)) {
console.log(exit.value) // 42
}
isSuccess(exit: Exit.Exit<XA, XE>exit)) {
resolve: (value: XA | PromiseLike<XA>) => voidresolve(exit: Exit.Success<XA, XE>(parameter) exit: {
_tag: "Success";
value: A;
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;
}
exit.Success<XA, XE>.value: XA extends Avalue)
} else {
reject: (reason?: any) => voidreject(import CauseCause.const squash: <E>(
self: Cause<E>
) => unknown
Collapses a Cause into a single unknown value, picking the "most
important" failure in this order:
When to use
Use to collapse a structured cause to the single value that synchronous and
promise runners would throw.
Details
- First
Fail error (the E value)
- First
Die defect
- A generic
Error("All fibers interrupted without error") for interrupt-only causes
- A generic
Error("Empty cause") for empty
This is the function used by Effect.runPromise and Effect.runSync to
decide what to throw.
Gotchas
This function is lossy. Use
prettyErrors
or iterate cause.reasons
when you need all failures.
Example (Squashing a cause)
import { Cause } from "effect"
console.log(Cause.squash(Cause.fail("error"))) // "error"
console.log(Cause.squash(Cause.die("defect"))) // "defect"
squash(exit: Exit.Failure<XA, XE>(parameter) exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
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;
}
exit.Failure<XA, XE>.cause: Cause.Cause<E>(property) Failure<XA, XE>.cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause))
}
})
)
)