9 releases
Uses new Rust 2024
| 0.1.5 | May 30, 2025 |
|---|---|
| 0.1.4 | May 17, 2025 |
| 0.1.2 | Apr 27, 2025 |
| 0.1.1 | Feb 21, 2025 |
| 0.0.0 | Nov 28, 2024 |
#549 in Asynchronous
269 downloads per month
Used in 7 crates
(6 directly)
29KB
471 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.
See the changelog for a full release history.
Feature flags
docs— Enables changelog and documentation of feature flags
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.3–4MB
~57K SLoC