scope!() { /* proc-macro */ }Expand description
Creates a structured concurrency scope.
The scope! macro creates a Scope binding for the
current Cx region and makes it available as scope inside the body.
Today this is an ergonomic binding helper, not a fresh child-region
boundary. For actual child-region ownership and quiescence, call
Scope::region explicitly.
§Syntax
ⓘ
scope!(cx, {
// body with spawned tasks
})
scope!(cx, state: &mut state, {
let _child = spawn!(async { work().await });
})§Arguments
cx- The capability context (&Cx)body- A block containing the scope’s workstate- Optional runtime state binding used by nestedspawn!calls
§Returns
The result of the scope body.
§Example
ⓘ
scope!(cx, state: &mut state, {
spawn!(async { work_a().await });
spawn!(async { work_b().await });
// Both tasks are awaited before scope exits
})