(u: unknown): u is Fiber<unknown, unknown>Checks whether a value is a Fiber. This is a type guard that can be used to determine if an unknown value is a Fiber instance.
When to use
Use when checking values at boundaries where an unknown value may be a runtime fiber.
Details
The check looks for the internal Fiber type ID marker and does not inspect the fiber's current state.
Example (Checking for fibers)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Test if values are fibers
console.log(Fiber.isFiber(fiber)) // true
console.log(Fiber.isFiber("hello")) // false
console.log(Fiber.isFiber(42)) // false
console.log(Fiber.isFiber(null)) // false
// Use as a type guard
const maybeValue: unknown = fiber
if (Fiber.isFiber(maybeValue)) {
// TypeScript knows maybeValue is a Fiber here
console.log(`Fiber ID: ${maybeValue.id}`)
}
})export const const isFiber: (
u: unknown
) => u is Fiber<unknown, unknown>
Checks whether a value is a Fiber. This is a type guard that can be used to
determine if an unknown value is a Fiber instance.
When to use
Use when checking values at boundaries where an unknown value may be a
runtime fiber.
Details
The check looks for the internal Fiber type ID marker and does not inspect
the fiber's current state.
Example (Checking for fibers)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Test if values are fibers
console.log(Fiber.isFiber(fiber)) // true
console.log(Fiber.isFiber("hello")) // false
console.log(Fiber.isFiber(42)) // false
console.log(Fiber.isFiber(null)) // false
// Use as a type guard
const maybeValue: unknown = fiber
if (Fiber.isFiber(maybeValue)) {
// TypeScript knows maybeValue is a Fiber here
console.log(`Fiber ID: ${maybeValue.id}`)
}
})
isFiber = (
u: unknownu: unknown
): u: unknownu is 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<unknown, unknown> => hasProperty<"~effect/Fiber/dev">(self: unknown, property: "~effect/Fiber/dev"): self is { [K in "~effect/Fiber/dev"]: unknown; } (+1 overload)Checks whether a value has a given property key.
When to use
Use when you need a Predicate guard for property access on unknown
values with a simple structural object check.
Details
Uses the in operator and isObjectKeyword. This does not check property
value types.
Example (Guarding object properties)
import { Predicate } from "effect"
const hasName = Predicate.hasProperty("name")
const data: unknown = { name: "Ada" }
if (hasName(data)) {
console.log(data.name)
}
hasProperty(u: unknownu, import effecteffect.const FiberTypeId: "~effect/Fiber/dev"FiberTypeId)