asio-grpc v3.3.0
Asynchronous gRPC with Asio/unified executors
Loading...
Searching...
No Matches
agrpc::BasicAlarm< Executor > Class Template Reference

I/O object for grpc::Alarm More...

#include <agrpc/alarm.hpp>

Public Types

using executor_type = Executor
 The executor type.
 

Public Member Functions

 BasicAlarm (const Executor &executor)
 Construct a BasicAlarm from an executor.
 
 BasicAlarm (agrpc::GrpcContext &grpc_context)
 Construct a BasicAlarm from a GrpcContext.
 
template<class Deadline , class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait (const Deadline &deadline, CompletionToken &&token=CompletionToken{}) &
 Wait until a specified deadline has been reached (lvalue overload)
 
template<class Deadline , class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait (const Deadline &deadline, CompletionToken &&token=CompletionToken{}) &&
 Wait until a specified deadline has been reached (rvalue overload)
 
void cancel ()
 Cancel an outstanding wait.
 
const executor_typeget_executor () const noexcept
 Get the executor.
 
const executor_typeget_scheduler () const noexcept
 Get the scheduler.
 

Detailed Description

template<class Executor>
class agrpc::BasicAlarm< Executor >

I/O object for grpc::Alarm

Wraps a grpc::Alarm as an I/O object.

Template Parameters
ExecutorThe executor type, must be capable of referring to a GrpcContext.

Per-Operation Cancellation

All. Effectively calls grpc::Alarm::Cancel which will cause the operation to complete with false.

Since
2.2.0

Member Function Documentation

◆ wait() [1/2]

template<class Executor >
template<class Deadline , class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto agrpc::BasicAlarm< Executor >::wait ( const Deadline & deadline,
CompletionToken && token = CompletionToken{} ) &
inline

Wait until a specified deadline has been reached (lvalue overload)

The operation finishes once the alarm expires (at deadline) or is cancelled. If the alarm expired, the result will be true, false otherwise (i.e. upon cancellation).

Attention
Only one wait may be outstanding at a time.

Example:

agrpc::Alarm alarm{grpc_context};
bool wait_ok = co_await alarm.wait(std::chrono::system_clock::now() + std::chrono::seconds(1), asio::use_awaitable);
Parameters
deadlineBy default gRPC supports two types of deadlines: gpr_timespec and std::chrono::system_clock::time_point. More types can be added by specializing grpc::TimePoint.
tokenA completion token like asio::yield_context or the one created by agrpc::use_sender. The completion signature is void(bool). true if it expired, false if it was canceled.

◆ wait() [2/2]

template<class Executor >
template<class Deadline , class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto agrpc::BasicAlarm< Executor >::wait ( const Deadline & deadline,
CompletionToken && token = CompletionToken{} ) &&
inline

Wait until a specified deadline has been reached (rvalue overload)

Extends the lifetime of the Alarm until the end of the wait. Otherwise, equivalent to the lvalue overload.

Example:

auto [alarm, wait_ok] = co_await agrpc::Alarm(grpc_context)
.wait(std::chrono::system_clock::now() + std::chrono::seconds(1), asio::use_awaitable);
Parameters
tokenA completion token like asio::yield_context or the one created by agrpc::use_sender. The completion signature is void(bool, BasicAlarm). true if it expired, false if it was canceled.

◆ cancel()

template<class Executor >
void agrpc::BasicAlarm< Executor >::cancel ( )
inline

Cancel an outstanding wait.

The outstanding wait will complete with false if the Alarm did not fire yet, otherwise this function has no effect.

Thread-safe

◆ get_executor()

template<class Executor >
const executor_type & agrpc::BasicAlarm< Executor >::get_executor ( ) const
inlinenodiscardnoexcept

Get the executor.

Thread-safe

◆ get_scheduler()

template<class Executor >
const executor_type & agrpc::BasicAlarm< Executor >::get_scheduler ( ) const
inlinenodiscardnoexcept

Get the scheduler.

Thread-safe

Since
2.9.0