pub struct Handle { /* private fields */ }
Expand description
A handle returned from constructing a new Context
. Used to cancel the context. You can
explicitly call cancel
, or, you can simply drop the Handle to cancel the context.
It’s also used to spawn new contexts. This fits cleaner into Rusts ownership system. We can only create new receivers by asking for them from the underlying Sender. This also ensures that only the owner of the context handle can generate more contexts for its chidlren.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn cancel(self)
pub fn cancel(self)
Cancels the Context, ensuring that done() returns immediately.
We only need to drop the handle, which will drop the sender. Doing so will close the
channel, causing done()
to immediately return.
Sourcepub fn spawn_ctx(&mut self) -> Context
pub fn spawn_ctx(&mut self) -> Context
Will spawn a context identical to the context that was created along with this Handle. Used to generate more receivers for receiving a cancel signal from the parent.
Sourcepub fn spawn_ref(&mut self) -> RefContext
pub fn spawn_ref(&mut self) -> RefContext
Will spawn a RefContext identical to the RefContext that was created along with this Handle. If a Context was created with this handle, it will spawn a RefContext version of the original Context.