(
scope: Scope,
options?: {
readonly startImmediately?: boolean | undefined
readonly uninterruptible?: boolean | "inherit" | undefined
}
): <A, E, R>(self: Effect<A, E, R>) => Effect<Fiber<A, E>, never, R>
<A, E, R>(
self: Effect<A, E, R>,
scope: Scope,
options?: {
readonly startImmediately?: boolean | undefined
readonly uninterruptible?: boolean | "inherit" | undefined
}
): Effect<Fiber<A, E>, never, R>Forks the effect in the specified scope. The fiber will be interrupted when the scope is closed.
Example (Forking into a supplied scope)
import { Effect } from "effect"
const task = Effect.gen(function*() {
yield* Effect.sleep("10 seconds")
return "completed"
})
const program = Effect.scoped(
Effect.gen(function*() {
const scope = yield* Effect.scope
const fiber = yield* Effect.forkIn(task, scope)
yield* Effect.sleep("1 second")
// Fiber will be interrupted when scope closes
return "done"
})
)export const const forkIn: {
(
scope: Scope,
options?: {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<Fiber<A, E>, never, R>
<A, E, R>(
self: Effect<A, E, R>,
scope: Scope,
options?: {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
): Effect<Fiber<A, E>, never, R>
}
Forks the effect in the specified scope. The fiber will be interrupted
when the scope is closed.
Example (Forking into a supplied scope)
import { Effect } from "effect"
const task = Effect.gen(function*() {
yield* Effect.sleep("10 seconds")
return "completed"
})
const program = Effect.scoped(
Effect.gen(function*() {
const scope = yield* Effect.scope
const fiber = yield* Effect.forkIn(task, scope)
yield* Effect.sleep("1 second")
// Fiber will be interrupted when scope closes
return "done"
})
)
forkIn: {
(
scope: Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: Scope,
options: | {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined
options?: {
readonly startImmediately?: boolean | undefinedstartImmediately?: boolean | undefined
readonly uninterruptible?: boolean | "inherit" | undefineduninterruptible?: boolean | "inherit" | undefined
}
): <function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>R>(self: Effect<A, E, R>(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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: 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 <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>R>) => 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<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<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>E>, never, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<Fiber<A, E>, never, R>R>
<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
R>(
self: Effect<A, E, R>(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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: 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 <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
R>,
scope: Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: Scope,
options: | {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined
options?: {
readonly startImmediately?: boolean | undefinedstartImmediately?: boolean | undefined
readonly uninterruptible?: boolean | "inherit" | undefineduninterruptible?: boolean | "inherit" | undefined
}
): 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<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<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
E>, never, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, scope: Scope, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
}): Effect<Fiber<A, E>, never, R>
R>
} = import internalinternal.const forkIn: {
(
scope: Scope.Scope,
options?: {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<Fiber.Fiber<A, E>, never, R>
<A, E, R>(
self: Effect.Effect<A, E, R>,
scope: Scope.Scope,
options?: {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
): Effect.Effect<Fiber.Fiber<A, E>, never, R>
}
forkIn