(
fiberId: number | undefined,
annotations?: Context.Context<never> | undefined
): <A, E>(self: Fiber<A, E>) => Effect<void>
<A, E>(
self: Fiber<A, E>,
fiberId: number | undefined,
annotations?: Context.Context<never> | undefined
): Effect<void>Interrupts a fiber with a specific fiber ID as the interruptor. This allows tracking which fiber initiated the interruption.
When to use
Use when runtime diagnostics or tracing should attribute the interruption to a specific fiber ID.
Details
The returned Effect completes only after the interrupted fiber has completed.
Gotchas
The supplied ID affects the recorded interruptor. It does not make interruption synchronous or force uninterruptible regions to stop early.
Example (Interrupting a fiber as another fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
const targetFiber = yield* Effect.forkChild(
Effect.delay("5 seconds")(Effect.succeed("task completed"))
)
// Interrupt the fiber, specifying fiber ID 123 as the interruptor
yield* Fiber.interruptAs(targetFiber, 123)
console.log("Fiber interrupted by fiber #123")
})export const const interruptAs: {
(
fiberId: number | undefined,
annotations?:
| Context.Context<never>
| undefined
): <A, E>(self: Fiber<A, E>) => Effect<void>
<A, E>(
self: Fiber<A, E>,
fiberId: number | undefined,
annotations?:
| Context.Context<never>
| undefined
): Effect<void>
}
Interrupts a fiber with a specific fiber ID as the interruptor. This allows
tracking which fiber initiated the interruption.
When to use
Use when runtime diagnostics or tracing should attribute the interruption to
a specific fiber ID.
Details
The returned Effect completes only after the interrupted fiber has completed.
Gotchas
The supplied ID affects the recorded interruptor. It does not make
interruption synchronous or force uninterruptible regions to stop early.
Example (Interrupting a fiber as another fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
const targetFiber = yield* Effect.forkChild(
Effect.delay("5 seconds")(Effect.succeed("task completed"))
)
// Interrupt the fiber, specifying fiber ID 123 as the interruptor
yield* Fiber.interruptAs(targetFiber, 123)
console.log("Fiber interrupted by fiber #123")
})
interruptAs: {
(
fiberId: number | undefinedfiberId: number | undefined,
annotations: Context.Context<never> | undefinedannotations?: import ContextContext.type Context.Context = /*unresolved*/ anyContext<never> | undefined
): <function (type parameter) A in <A, E>(self: Fiber<A, E>): Effect<void>A, function (type parameter) E in <A, E>(self: Fiber<A, E>): Effect<void>E>(self: Fiber<A, E>(parameter) self: {
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; <…;
}
self: 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>(self: Fiber<A, E>): Effect<void>A, function (type parameter) E in <A, E>(self: Fiber<A, E>): Effect<void>E>) => import EffectEffect<void>
<function (type parameter) A in <A, E>(self: Fiber<A, E>, fiberId: number | undefined, annotations?: Context.Context<never> | undefined): Effect<void>A, function (type parameter) E in <A, E>(self: Fiber<A, E>, fiberId: number | undefined, annotations?: Context.Context<never> | undefined): Effect<void>E>(
self: Fiber<A, E>(parameter) self: {
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; <…;
}
self: 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>(self: Fiber<A, E>, fiberId: number | undefined, annotations?: Context.Context<never> | undefined): Effect<void>A, function (type parameter) E in <A, E>(self: Fiber<A, E>, fiberId: number | undefined, annotations?: Context.Context<never> | undefined): Effect<void>E>,
fiberId: number | undefinedfiberId: number | undefined,
annotations: Context.Context<never> | undefinedannotations?: import ContextContext.type Context.Context = /*unresolved*/ anyContext<never> | undefined
): import EffectEffect<void>
} = import effecteffect.const fiberInterruptAs: {
(
fiberId: number | undefined,
annotations?:
| Context.Context<never>
| undefined
): <A, E>(
self: Fiber.Fiber<A, E>
) => Effect.Effect<void>
<A, E>(
self: Fiber.Fiber<A, E>,
fiberId: number | undefined,
annotations?:
| Context.Context<never>
| undefined
): Effect.Effect<void>
}
fiberInterruptAs