boost::corosio::cancel_after
Cancel an operation if it does not complete within a duration.
Synopsis
Declared in <boost/corosio/cancel.hpp>
auto
cancel_after(
auto&& op,
timer::duration timeout);
Description
Convenience overload that creates a timer internally. Equivalent to cancel_at( op, clock::now() + timeout ).
Completion Conditions
The returned awaitable resumes when either:
-
The inner operation completes (successfully or with error).
-
The timeout elapses and the inner operation is cancelled.
-
The caller's stop token is triggered, cancelling both.
Error Conditions
-
On timeout or parent cancellation, the inner operation completes with an error equal to `capy::cond::canceled`.
-
All other errors are propagated from the inner operation.
|
Creates a timer per call. Use the explicit‐timer overload to amortize allocation across multiple timeouts. |
Example
auto [ec, n] = co_await cancel_after(
sock.read_some( buf ), 5s );
if (ec == capy::cond::canceled)
// timed out
Parameters
| Name | Description |
|---|---|
op |
The inner I/O awaitable to wrap. |
timeout |
The relative duration after which to cancel. |
See Also
cancel_at
Created with MrDocs