boost::corosio::timer

An asynchronous timer for coroutine I/O.

Synopsis

Declared in <boost/corosio/timer.hpp>

class timer
    : public io_timer

Description

This class provides asynchronous timer operations that return awaitable types. The timer can be used to schedule operations to occur after a specified duration or at a specific time point.

Multiple coroutines may wait concurrently on the same timer. When the timer expires, all waiters complete with success. When the timer is cancelled, all waiters complete with an error that compares equal to capy::cond::canceled.

Each timer operation participates in the affine awaitable protocol, ensuring coroutines resume on the correct executor.

Thread Safety

Distinct objects: Safe. Shared objects: Unsafe.

Semantics

Timers are not backed by per‐timer kernel objects. The io_context's timer service keeps a process‐side min‐heap of pending expirations; the nearest expiry drives the reactor's poll timeout, and expirations are processed in the run loop.

Base Classes

Name

Description

io_timer

Abstract base for asynchronous timers.

Types

Name

Description

handle

RAII wrapper for I/O object implementation lifetime.

implementation

Backend interface for timer wait operations.

io_service

Service interface for I/O object lifecycle management.

Type Aliases

Name

Description

clock_type

The clock type used for time operations.

duration

The duration type for relative expiry times.

implementation

Alias for backward compatibility.

time_point

The time point type for absolute expiry times.

Member Functions

Name

Description

timer [constructor] [deleted]

Constructors

~timer [destructor] [virtual]

Destructor.

operator= [deleted]

Move assignment operator.

cancel

Cancel all pending asynchronous wait operations.

cancel_one

Cancel one pending asynchronous wait operation.

context

Return the execution context.

expires_after

Set the timer's expiry time relative to now.

expires_at

Set the timer's expiry time as an absolute time.

expiry

Return the timer's expiry time as an absolute time.

wait

Wait for the timer to expire.

Protected Member Functions

Name

Description

timer [constructor]

Construct from handle

operator= [deleted]

Assignment operators

do_cancel [virtual]

Dispatch cancel to the concrete implementation.

get

Return the underlying implementation.

Protected Static Member Functions

Name

Description

create_handle

Create a handle bound to a service found in the context.

Protected Data Members

Name

Description

h_

The platform I/O handle owned by this object.

Derived Classes

Name

Description

native_timer

An asynchronous timer with devirtualized wait operations.

Created with MrDocs