Crates.io | tokio-scoped |
lib.rs | tokio-scoped |
version | 0.2.0 |
source | src |
created_at | 2018-09-06 14:32:58.939478 |
updated_at | 2022-03-08 14:53:44.469998 |
description | Scoped Runtime for tokio |
homepage | https://github.com/Snnappie/tokio-scoped |
repository | https://github.com/Snnappie/tokio-scoped |
max_upload_size | |
id | 83177 |
size | 16,092 |
tokio-scoped provides a scope
function inspired by crossbeam
but for the tokio
Runtime. A scope allows one to spawn futures which do not have a 'static
lifetime
by ensuring each future spawned in the scope completes before the scope exits.
#[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!");
}