4 releases
new 0.1.0 | Feb 10, 2025 |
---|---|
0.0.3 |
|
0.0.2 | Dec 8, 2024 |
0.0.1 | Dec 1, 2024 |
0.0.0 | Nov 28, 2024 |
#342 in Asynchronous
65 downloads per month
Used in 6 crates
(5 directly)
24KB
448 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.7–8MB
~59K SLoC