pub struct Context { /* private fields */ }
Expand description
A context for cancelling futures and waiting for shutdown.
A context can be created from a handler by calling Handler::context
or
from another context by calling Context::new_child
so to have a
hierarchy of contexts.
Contexts can then be attached to futures or streams in order to
automatically cancel them when the context is done, when invoking
Handler::cancel
.
The Handler::shutdown
method will block until all contexts have been
dropped allowing for a graceful shutdown.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> (Self, Handler)
pub fn new() -> (Self, Handler)
Create a new context using the global handler. Returns a child context and child handler of the global handler.
Sourcepub fn new_child(&self) -> (Self, Handler)
pub fn new_child(&self) -> (Self, Handler)
Create a new child context from this context. Returns a new child context and child handler of this context.
§Example
use scuffle_context::Context;
let (parent, parent_handler) = Context::new();
let (child, child_handler) = parent.new_child();
Sourcepub async fn into_done(self)
pub async fn into_done(self)
The same as Context::done
but takes ownership of the context.