Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cause of cancel cancelation token #5249

Open
rekby opened this issue Nov 30, 2022 · 0 comments
Open

Add cause of cancel cancelation token #5249

rekby opened this issue Nov 30, 2022 · 0 comments
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request. M-sync Module: tokio/sync

Comments

@rekby
Copy link

rekby commented Nov 30, 2022

Is your feature request related to a problem? Please describe.
Log reason of token cancelation - it helps with debug process.

Describe the solution you'd like
I want add functions to struct CancellationToken

fun cancel_with_cause<T: Into<CancelationCause>>(cause: T) {}
fun cancel_cause()->Option<CancelCause> {}

with causes

#[non_exhaustive]
enum CancelationCause{
    Empty, // used for cancel with cancel() func - without specified cause
    Str(&'static str),
    String(String),
    Err(Box<std::error::Error + Send + Sync>),
    Debug(Box<std::fmt::Debug + Send + Sync>),
    Any(std::any::Any)
}

cancel_with_cause - allow set cause of cancelation
cancel_cause - check if token cancelled and reason of it.

Describe alternatives you've considered

  • create trait, with default implementation for CancellationToken (will need box for usage as trait)
  • create other type for cancel with reason (split code for incompatible parts: with and without support reason).

Additional context
Similar functional will add in standard lib of go1.20:
golang/go#51365
golang/go@5b42f89

@rekby rekby added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Nov 30, 2022
@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync and removed A-tokio Area: The main tokio crate labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request. M-sync Module: tokio/sync
Projects
None yet
Development

No branches or pull requests

2 participants