Skip to content

Latest commit

 

History

History

context

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

scuffle-context

Warning

This crate is under active development and may not be stable.

crates.io docs.rs


A crate designed to provide the ability to cancel futures using a context go-like approach, allowing for graceful shutdowns and cancellations.

Why do we need this?

Its often useful to wait for all the futures to shutdown or to cancel them when we no longer care about the results. This crate provides an interface to cancel all futures associated with a context or wait for them to finish before shutting down. Allowing for graceful shutdowns and cancellations.

Usage

Here is an example of how to use the Context to cancel a spawned task.

let (ctx, handler) = Context::new();

tokio::spawn(async {
    // Do some work
    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
}.with_context(ctx));

// Will stop the spawned task and cancel all associated futures.
handler.cancel();

License

This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.

SPDX-License-Identifier: MIT OR Apache-2.0