Add a CancellationToken
method for running a future until completion or cancellation
#6566
Labels
A-tokio-util
Area: The tokio-util crate
C-feature-request
Category: A feature request.
M-sync
Module: tokio/sync
(This is a variant of the idea proposed in #4598; I was advised to create a new issue for this.)
Give how (seemingly) often a
tokio_util::sync::CancellationToken
gets used as follows:I propose adding a method to
CancellationToken
that takes aFuture
, runs it to completion, and returns its output — unless the token is cancelled before the future completes, in which case the future is dropped. I feel the best type for the result of this composed future would be anOption<Fut::Output>
, withNone
indicating cancellation.Example usage of this new method (here called
run_until_cancelled()
):The text was updated successfully, but these errors were encountered: