pub struct RequestCancellation { /* private fields */ }unstable_cancel_request only.Expand description
A request-local marker that is set when the peer asks to cancel the request.
Request handlers can get this handle from Responder::cancellation and
use it from spawned work to stop long-running request processing
cooperatively.
Implementations§
Source§impl RequestCancellation
impl RequestCancellation
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Wait until the peer sends $/cancel_request for this request.
If cancellation was already requested, this returns immediately.
Sourcepub async fn run_until_cancelled<T>(
&self,
future: impl Future<Output = Result<T, Error>>,
) -> Result<T, Error>
pub async fn run_until_cancelled<T>( &self, future: impl Future<Output = Result<T, Error>>, ) -> Result<T, Error>
Run request work until it completes or the peer asks to cancel it.
If cancellation is requested first, this returns
Error::request_cancelled. This is a convenience for request handlers
that want to respond with the normal result or the standard
cancellation error.
When cancellation wins, future is dropped: work stops at its next
await point, partial results are lost, and any cleanup must happen in
Drop implementations. Handlers that need to flush partial results or
run async cleanup should instead watch cancelled
or poll is_cancelled from inside the work.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns whether the peer has already requested cancellation.
Trait Implementations§
Source§impl Clone for RequestCancellation
impl Clone for RequestCancellation
Source§fn clone(&self) -> RequestCancellation
fn clone(&self) -> RequestCancellation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more