Skip to content
Beskid The Beskid Book

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

11.2 Fibers and spawn

Start cooperative fibers with spawn, Fiber handles, join, detach, and cancel.

Fibers and spawn

Fiber<i32> worker = spawn DoWork(42);

spawn is not “fire a thread.” It schedules a cooperative fiber with a typed handle.

Every spawn expression must type-check to Fiber<T> where T is the entry callable’s return type (Concurrency.Fiber in corelib_concurrency). You do not get T directly from spawn—use Join.

Normative feature: Fibers and spawn.

The handle exposes OnCancelled as an event on the child fiber handle, not on the entry callable. Cancellation flows: Cancel → observe OnCancelledJoin / channel errors per the decisions record.

RuleConsequence
Stack references must not escape spawnStackReferenceEscapesSpawn diagnostic
Detach waives shutdown joinOtherwise runtime joins non-detached children when main returns
Cross-fiber payloadChannels only — not mutex-as-mailbox

beskid_codegen emits fiber_spawn with environment captures rooted for GC. Runtime details: Fiber scheduler and stacks.

Channels preview