<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>Retrieves the fiber from the FiberHandle synchronously.
When to use
Use when synchronous inspection of the current fiber is needed and an
Option result is enough outside the Effect workflow.
Example (Reading the current fiber unsafely)
import { Effect, FiberHandle } from "effect"
Effect.gen(function*() {
const handle = yield* FiberHandle.make()
// No fiber initially
const emptyFiber = FiberHandle.getUnsafe(handle)
console.log(emptyFiber._tag === "None") // true
// Add a fiber
yield* FiberHandle.run(handle, Effect.succeed("hello"))
const fiber = FiberHandle.getUnsafe(handle)
console.log(fiber._tag === "Some") // true
})export function function getUnsafe<A, E>(
self: FiberHandle<A, E>
): Option.Option<Fiber.Fiber<A, E>>
Retrieves the fiber from the FiberHandle synchronously.
When to use
Use when synchronous inspection of the current fiber is needed and an
Option result is enough outside the Effect workflow.
Example (Reading the current fiber unsafely)
import { Effect, FiberHandle } from "effect"
Effect.gen(function*() {
const handle = yield* FiberHandle.make()
// No fiber initially
const emptyFiber = FiberHandle.getUnsafe(handle)
console.log(emptyFiber._tag === "None") // true
// Add a fiber
yield* FiberHandle.run(handle, Effect.succeed("hello"))
const fiber = FiberHandle.getUnsafe(handle)
console.log(fiber._tag === "Some") // true
})
getUnsafe<function (type parameter) A in getUnsafe<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>A, function (type parameter) E in getUnsafe<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>E>(self: FiberHandle<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; fiber: Fiber.Fiber<A, E> | undefined } | { readonly _tag: "Closed" };
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface FiberHandle<out A = unknown, out E = unknown>Scoped handle that manages at most one fiber, interrupts the current fiber
when the handle's scope closes, and removes managed fibers from the handle
when they complete.
Example (Managing a single fiber)
import { Effect, Fiber, FiberHandle } from "effect"
Effect.gen(function*() {
// Create a FiberHandle that can hold fibers producing strings
const handle = yield* FiberHandle.make<string, never>()
// The handle can store and manage a single fiber
const fiber = yield* FiberHandle.run(handle, Effect.succeed("hello"))
const result = yield* Fiber.await(fiber)
console.log(result) // "hello"
})
FiberHandle<function (type parameter) A in getUnsafe<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>A, function (type parameter) E in getUnsafe<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>E>): import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<import FiberFiber.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 getUnsafe<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>A, function (type parameter) E in getUnsafe<A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.Fiber<A, E>>E>> {
return self: FiberHandle<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; fiber: Fiber.Fiber<A, E> | undefined } | { readonly _tag: "Closed" };
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.FiberHandle<A, E>.state: { readonly _tag: "Open"; fiber: Fiber.Fiber<A, E> | undefined } | { readonly _tag: "Closed" }state._tag: "Open" | "Closed"_tag === "Closed" ? import OptionOption.const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none() : import OptionOption.const fromUndefinedOr: <A>(
a: A
) => Option<Exclude<A, undefined>>
Converts a possibly undefined value into an Option, leaving null
as a valid Some.
When to use
Use when you want to treat only undefined as absent while preserving null
as a meaningful value.
Details
undefined → None
- Any other value (including
null) → Some
Example (Converting possibly undefined values to an Option)
import { Option } from "effect"
console.log(Option.fromUndefinedOr(undefined))
// Output: { _id: 'Option', _tag: 'None' }
console.log(Option.fromUndefinedOr(null))
// Output: { _id: 'Option', _tag: 'Some', value: null }
console.log(Option.fromUndefinedOr(42))
// Output: { _id: 'Option', _tag: 'Some', value: 42 }
fromUndefinedOr(self: FiberHandle<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; fiber: Fiber.Fiber<A, E> | undefined } | { readonly _tag: "Closed" };
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.FiberHandle<A, E>.state: { readonly _tag: "Open"; fiber: Fiber.Fiber<A, E> | undefined } | { readonly _tag: "Closed" }state.fiber: Fiber.Fiber<A, E> | undefinedfiber)
}