6 releases
Uses new Rust 2024
new 0.1.2 | Apr 27, 2025 |
---|---|
0.1.1 | Feb 21, 2025 |
0.0.3 |
|
0.0.2 | Dec 8, 2024 |
0.0.0 | Nov 28, 2024 |
#221 in Asynchronous
1,726 downloads per month
Used in 7 crates
(6 directly)
26KB
462 lines
scuffle-context
[!WARNING]
This crate is under active development and may not be stable.
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
Dependencies
~2.8–8.5MB
~60K SLoC