pub struct RequestCancellation { /* private fields */ }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.
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.
§Errors
Returns Error::request_cancelled if cancellation wins, or the
future’s own error if it finishes first.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns whether the peer has already requested cancellation.