<A extends Iterable<Fiber<any, any>>>(fibers: A): Effect<void>Interrupts all fibers in the provided iterable, causing them to stop executing and clean up any acquired resources.
When to use
Use when you need to cancel several forked fibers and wait for their cleanup to complete.
Details
The current fiber is recorded as the interruptor. The returned Effect completes only after all interrupted fibers have completed.
Gotchas
Interruption is cooperative for each fiber. The returned Effect can wait for uninterruptible work and finalizers in any interrupted fiber.
Example (Interrupting multiple fibers)
import { Console, Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create multiple long-running fibers
const fiber1 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("5 seconds")
yield* Console.log("Task 1 completed")
return "result1"
})
)
const fiber2 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("3 seconds")
yield* Console.log("Task 2 completed")
return "result2"
})
)
const fiber3 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("4 seconds")
yield* Console.log("Task 3 completed")
return "result3"
})
)
// Wait a bit, then interrupt all fibers
yield* Effect.sleep("1 second")
yield* Console.log("Interrupting all fibers...")
yield* Fiber.interruptAll([fiber1, fiber2, fiber3])
yield* Console.log("All fibers have been interrupted")
})export const const interruptAll: <
A extends Iterable<Fiber<any, any>>
>(
fibers: A
) => Effect<void>
Interrupts all fibers in the provided iterable, causing them to stop executing
and clean up any acquired resources.
When to use
Use when you need to cancel several forked fibers and wait for their cleanup
to complete.
Details
The current fiber is recorded as the interruptor. The returned Effect
completes only after all interrupted fibers have completed.
Gotchas
Interruption is cooperative for each fiber. The returned Effect can wait for
uninterruptible work and finalizers in any interrupted fiber.
Example (Interrupting multiple fibers)
import { Console, Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create multiple long-running fibers
const fiber1 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("5 seconds")
yield* Console.log("Task 1 completed")
return "result1"
})
)
const fiber2 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("3 seconds")
yield* Console.log("Task 2 completed")
return "result2"
})
)
const fiber3 = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("4 seconds")
yield* Console.log("Task 3 completed")
return "result3"
})
)
// Wait a bit, then interrupt all fibers
yield* Effect.sleep("1 second")
yield* Console.log("Interrupting all fibers...")
yield* Fiber.interruptAll([fiber1, fiber2, fiber3])
yield* Console.log("All fibers have been interrupted")
})
interruptAll: <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> = import effecteffect.const fiberInterruptAll: <
A extends Iterable<Fiber.Fiber<any, any>>
>(
fibers: A
) => Effect.Effect<void>
fiberInterruptAll