Function tokio_scoped::scope
source · [−]Expand description
Creates a Scope
using the current tokio runtime and calls the scope
method with the
provided future
Example
#[tokio::main]
async fn main() {
let mut v = String::from("Hello");
tokio_scoped::scope(|scope| {
// Use the scope to spawn the future.
scope.spawn(async {
v.push('!');
});
});
// The scope won't exit until all spawned futures are complete.
assert_eq!(v.as_str(), "Hello!");
}