Function tokio_scoped::scoped
source · [−]pub fn scoped(tokio_handle: &Handle) -> ScopeBuilder<'_>
Expand description
Borrows a Handle
to the tokio Runtime
to construct a ScopeBuilder
which can be used to
create a scope.
Example
let mut v = String::from("Hello");
let rt = tokio::runtime::Runtime::new().unwrap();
tokio_scoped::scoped(rt.handle()).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!");