boost::capy::delay_awaitable

IoAwaitable returned by delay.

Synopsis

Declared in <boost/capy/delay.hpp>

class delay_awaitable;

Description

Suspends the calling coroutine until the deadline elapses or the environment's stop token is activated, whichever comes first. Resumption is always posted through the executor, never inline on the timer thread.

Not intended to be named directly; use the delay factory function instead.

Return Value

Returns io_result<>{} (no error) when the timer fires normally, or io_result<>{error::canceled} when cancellation claims the resume before the deadline.

Cancellation

If stop_requested() is true before suspension, the coroutine resumes immediately without scheduling a timer and returns io_result<>{error::canceled}. If stop is requested while suspended, the stop callback claims the resume and posts it through the executor; the pending timer is cancelled on the next await_resume or destructor call.

Thread Safety

A single delay_awaitable must not be awaited concurrently. Multiple independent delay() calls on the same execution_context are safe and share one timer thread.

Member Functions

Name

Description

delay_awaitable [constructor] [deleted]

Construct an awaitable that waits for dur nanoseconds. Prefer the delay factory over constructing directly.

~delay_awaitable [destructor]

Tear down any registered stop callback and cancel the pending timer if one is still scheduled.

operator= [deleted]

await_ready

Return true for zero or negative durations, completing synchronously without scheduling a timer.

await_resume

Clean up the stop callback and timer, then return io_result<>{error::canceled} if cancellation claimed the resume, or an empty io_result<> otherwise.

await_suspend

Suspend the coroutine, scheduling the timer and a stop callback on the environment's executor and stop token. Resumes h immediately if stop was already requested.

Non-Member Functions

Name

Description

delay

Suspend the current coroutine for a duration.

See Also

delay, timeout

Created with MrDocs