boost::asio::cancel_after

Adapt a completion_token to cancel an operation if not complete before the specified relative timeout has elapsed.

Synopsis

Declared in <boost/asio/cancel_after.hpp>

template<
    typename Rep,
    typename Period,
    typename CompletionToken>
[[nodiscard]]
cancel_after_t<decay_t<CompletionToken>, std::chrono::steady_clock>
cancel_after(
    chrono::duration<Rep, Period> const& timeout,
    CompletionToken&& completion_token);

Description

Thread Safety

When an asynchronous operation is used with cancel_after, a timer async_wait operation is performed in parallel to the main operation. If this parallel async_wait completes first, a cancellation request is emitted to cancel the main operation. Consequently, the application must ensure that the asynchronous operation is performed within an implicit or explicit strand.

Return Value

A completion_token adapter that cancels an operation after a timeout.

Created with MrDocs