Crate tokio_scoped[][src]

A scoped tokio Runtime that can be used to create Scopes which can spawn futures which can access stack data. That is, the futures spawned by the Scope do not require the 'static lifetime bound. This can be done safely by ensuring that the Scope doesn't exit until all spawned futures have finished executing. Be aware, that when a Scope exits it will block until every future spawned by the Scope completes. Therefore, one should take caution when created scopes within an asynchronous context, such as from within another spawned future.

Example


let mut v = String::from("Hello");
tokio_scoped::scope(|scope| {
    // Use the scope to spawn the future.
    scope.spawn(lazy(|| {
        v.push('!');
        Ok(())
    }));
});
// The scope won't exit until all spawned futures are complete.
assert_eq!(v.as_str(), "Hello!");

See also crossbeam::scope

Structs

Scope
ScopeBuilder

Struct used to build scopes from a borrowed Runtime. Generally users should use the scoped function instead of building ScopeBuilder instances directly.

ScopedRuntime

Wrapper type around a tokio Runtime which can be used to create Scopes. This type takes ownership of the Runtime. For an alternative approach that

Functions

scope

Creates a ScopedRuntime and calls the scope method with f on it.

scoped

Borrows the Runtime to construct a ScopeBuilder which can be used to create a scope.