Hyperlinkv0.8.0-beta.28

Fiber

Fiber.interruptAsconsteffect/Fiber.ts:387
(
  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")
})
interruptioninterrupt
Source effect/Fiber.ts:38711 lines
export 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>
} = effect.fiberInterruptAs
Referenced by 3 symbols