(): Fiber<any, any> | undefinedReturns the current fiber if called from within a fiber context,
otherwise returns undefined.
When to use
Use when you need low-level runtime integrations that need access to the currently executing fiber.
Gotchas
This is a synchronous accessor, not an Effect. It returns undefined outside
an active fiber runtime context.
Example (Getting the current fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
const current = Fiber.getCurrent()
if (current) {
console.log(`Current fiber ID: ${current.id}`)
}
})export const const getCurrent: () =>
| Fiber<any, any>
| undefined
Returns the current fiber if called from within a fiber context,
otherwise returns undefined.
When to use
Use when you need low-level runtime integrations that need access to the currently
executing fiber.
Gotchas
This is a synchronous accessor, not an Effect. It returns undefined outside
an active fiber runtime context.
Example (Getting the current fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
const current = Fiber.getCurrent()
if (current) {
console.log(`Current fiber ID: ${current.id}`)
}
})
getCurrent: () => 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> | undefined = import effecteffect.const getCurrentFiber: () =>
| Fiber.Fiber<any, any>
| undefined
getCurrentFiber