spawn!() { /* proc-macro */ }Expand description
Spawns a task within the current scope.
The spawn! macro expands to [Scope::spawn_registered], so it requires
ambient __state and __cx bindings in addition to the target Scope.
The easiest supported path is to use it inside scope!(..., state: ..., { ... }).
§Syntax
ⓘ
spawn!(async { /* work */ })
spawn!(async move { /* work with captured values */ })§Returns
A TaskHandle that can be awaited to get the task’s result.
§Example
ⓘ
let handle = spawn!(async {
expensive_computation().await
});
let result = handle.await;