(fiberId: number): <A extends Iterable<Fiber<any, any>>>(
fibers: A
) => Effect<void>
<A extends Iterable<Fiber<any, any>>>(
fibers: A,
fiberId: number
): Effect<void>Interrupts all fibers in the provided iterable using the specified fiber ID as the interrupting fiber. This allows you to control which fiber is considered the source of the interruption, which can be useful for debugging and tracing.
When to use
Use to interrupt several fibers while recording a specific fiber ID as the interruptor.
Details
The returned Effect completes only after all interrupted fibers have completed.
Gotchas
The supplied ID affects the recorded interruptor. It does not make interruption synchronous or force uninterruptible regions to stop early.
Example (Interrupting multiple fibers as another fiber)
import { Console, Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a controlling fiber
const controllerFiber = yield* Effect.forkChild(Effect.succeed("controller"))
// Create multiple worker fibers
const worker1 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("5 seconds")
yield* Console.log("Worker 1 completed")
return "worker1"
})
)
const worker2 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("3 seconds")
yield* Console.log("Worker 2 completed")
return "worker2"
})
)
// Interrupt all workers using the controller fiber's ID
yield* Effect.sleep("1 second")
yield* Console.log("Interrupting workers from controller...")
yield* Fiber.interruptAllAs([worker1, worker2], controllerFiber.id)
yield* Console.log("All workers interrupted by controller")
})export const const interruptAllAs: {
(fiberId: number): <
A extends Iterable<Fiber<any, any>>
>(
fibers: A
) => Effect<void>
<A extends Iterable<Fiber<any, any>>>(
fibers: A,
fiberId: number
): Effect<void>
}
Interrupts all fibers in the provided iterable using the specified fiber ID as the
interrupting fiber. This allows you to control which fiber is considered the source
of the interruption, which can be useful for debugging and tracing.
When to use
Use to interrupt several fibers while recording a specific fiber ID as the
interruptor.
Details
The returned Effect completes only after all interrupted fibers have
completed.
Gotchas
The supplied ID affects the recorded interruptor. It does not make
interruption synchronous or force uninterruptible regions to stop early.
Example (Interrupting multiple fibers as another fiber)
import { Console, Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a controlling fiber
const controllerFiber = yield* Effect.forkChild(Effect.succeed("controller"))
// Create multiple worker fibers
const worker1 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("5 seconds")
yield* Console.log("Worker 1 completed")
return "worker1"
})
)
const worker2 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("3 seconds")
yield* Console.log("Worker 2 completed")
return "worker2"
})
)
// Interrupt all workers using the controller fiber's ID
yield* Effect.sleep("1 second")
yield* Console.log("Interrupting workers from controller...")
yield* Fiber.interruptAllAs([worker1, worker2], controllerFiber.id)
yield* Console.log("All workers interrupted by controller")
})
interruptAllAs: {
(fiberId: numberfiberId: number): <function (type parameter) A in <A extends Iterable<Fiber<any, any>>>(fibers: A): Effect<void>A extends interface Iterable<T, TReturn = any, TNext = any>Iterable<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>>>(fibers: A extends Iterable<Fiber<any, any>>fibers: function (type parameter) A in <A extends Iterable<Fiber<any, any>>>(fibers: A): Effect<void>A) => import EffectEffect<void>
<function (type parameter) A in <A extends Iterable<Fiber<any, any>>>(fibers: A, fiberId: number): Effect<void>A extends interface Iterable<T, TReturn = any, TNext = any>Iterable<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>>>(fibers: A extends Iterable<Fiber<any, any>>fibers: function (type parameter) A in <A extends Iterable<Fiber<any, any>>>(fibers: A, fiberId: number): Effect<void>A, fiberId: numberfiberId: number): import EffectEffect<void>
} = import effecteffect.const fiberInterruptAllAs: {
(fiberId: number): <
A extends Iterable<Fiber.Fiber<any, any>>
>(
fibers: A
) => Effect.Effect<void>
<A extends Iterable<Fiber.Fiber<any, any>>>(
fibers: A,
fiberId: number
): Effect.Effect<void>
}
fiberInterruptAllAs