Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Fibers and spawn

Platform spec feature

Fibers and spawn

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

What this feature specifies

The spawn keyword starts cooperative fibers. Every spawn expression must type-check to Fiber<T> (Concurrency.Fiber in corelib_concurrency) where T is the entry return type. There is no async / await; cross-fiber payloads use Channel<T> only. Reserved async / await tokens are compile errors.

Implementation anchors

Contract statement

Beskid provides a spawn keyword for cooperative concurrency. Every spawn expression must type-check against the Fiber<T> contract defined in corelib_concurrency (Concurrency.Fiber), where T is the return type of the spawned callable.

There is no async / await surface in the language. Structured concurrency uses Join, Channel Send/Receive, WaitGroup, and Hub.

Syntax

`Fiber<T>` handle = spawn Callable(/* args */);
  • Callable — function or closure satisfying the spawn contract (see semantic rules).
  • Lowering produces runtime fiber_spawn with environment captures rooted for GC.
  • spawn is not an expression that returns T directly; use Join for Result<T, FiberError>.

Fiber handle

spawn returns Fiber<T> where T is the entry callable’s return type. The handle struct (corelib) must expose:

event OnCancelled();

The entry callable is a normal function or closure — it does not declare OnCancelled. Cancellation is observed on the child fiber via the handle’s event, then Join / channel Result errors per decisions record.

Semantic rules

  1. Spawn target — callable return type T determines Fiber<T>; entry signature must be compatible with spawn lowering.
  2. Captures — closure captures must not leak stack references across fibers; StackReferenceEscapesSpawn diagnostic.
  3. Detach — explicit Detach waives shutdown Join; otherwise runtime joins non-detached children when main returns.
  4. CancelCancel + OnCancelled on handle + Join / channel Cancelled (normative ordering in decisions record).
  5. Cross-fiber dataChannel only; Mutex / WaitGroup coordinate invariants, not payload transfer.
  6. Join cycle — child (or descendant) Join on parent / ancestor handle is JoinWouldDeadlock (compile error).
  7. Reserved keywordsasync and await are errors if parsed (not implemented).

Relationship to events

Language event members remain for single-fiber multicast within one fiber’s ownership. Delivering UI or IO notifications to another fiber must use Channel (see Events and console spec).

Diagnostics

CodeWhen
SpawnTargetNotFiberCompatibleSpawned callable not a valid spawn entry (signature / captures)
JoinWouldDeadlockJoin would wait on an ancestor fiber handle
StackReferenceEscapesSpawnCapture would share stack memory across fibers
AsyncKeywordReservedasync token in source
AwaitKeywordReservedawait token in source

No open decisions. Closed choices are normative ADRs under adr/ (D-LMETA-FIBERS-0001D-LMETA-FIBERS-0005); use the reader ADRs tab for detail. Fiber/async keyword policy is also recorded in inception D-INC-0008 (not duplicated here).