Manual
Scopes and frames
Which operation code belongs to (a Scope), and which run() owns its coroutines (a Frame).
Introduction#
A frame (Frame) is the lifetime: which run() waits for a coroutine, and what a cancellation or a deadline reaches. A scope (\Scope, from fiber-interop/scope) is the identity: which request or job the code belongs to, independent of which frame it runs in. go() always joins the frame of the coroutine that calls it; only run() and phasync::service start one outside it. See Advanced: Coroutines for how the two interact.
Examples#
- All examples of this topic – 8 with their output.
Reference#
phasync::onScopeChange– Registers $fn to be called when the current Scope changes as the event loop switches coroutines.phasync::frame– Returns the frame of the running coroutine: that of the innermost run() it is in.Frame– The lifetime of a phasync::run() call: the coroutines started inside it, which it waits for, cancels and rethrows.