Skuld.FiberPool.Main (skuld v0.30.0)

View Source

Main computation driver for the FiberPool.

Orchestrates fiber execution on behalf of the main computation. Called from two sites — each handling a different class of pending work:

  • InternalSuspend.ISentinel.run — drains InternalSuspend sentinels (Await, Batch, Channel) at the Comp.run boundary. When the main computation awaits fiber results and suspends, the scheduler steps fibers until the await is satisfied, then resumes the main computation.
  • FiberPool.with_handler — drains fire-and-forget fibers (spawned but not awaited) on normal completion, while scoped effect state is still live.

This module does not schedule individual fibers — that's Scheduler's job. It sits one level above, calling Scheduler.step/2 in a loop while checking whether the main computation can proceed.

Dependency Layering

  • InternalSuspend depends on this module (via ISentinel.run → drain_pending)
  • Skuld.Effects.FiberPool depends on this module (via with_handler)
  • Both depend on Comp and Skuld.Coroutine.*
  • Comp does not depend on any Fiber module

InternalSuspend sentinels propagate through Comp.bind without firing continuations, so drain_comp inside FiberPool.with_handler cannot intercept them. ISentinel at the Comp.run boundary is the natural dispatch point.

Summary

Functions

Drain any pending fibers and tasks accumulated during computation execution.

Functions

drain_pending(result, env)

@spec drain_pending(term(), Skuld.Comp.Types.env()) ::
  {term(), Skuld.Comp.Types.env()}

Drain any pending fibers and tasks accumulated during computation execution.

Called by Comp.run/1 after Comp.call/3. If no fibers or tasks are pending (and the result is not an await suspension), this is a fast-path no-op.

Returns {result, env} — either the original values unchanged (fast path) or the final values after all fibers and tasks have completed.