SObjectizer-5 Extra
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
so_5::extra::revocable_timer::timer_id_t Class Referencefinal

The ID of revocable timer message/signal. More...

#include <pub.hpp>

Public Member Functions

 timer_id_t ()=default
 ~timer_id_t () noexcept
 timer_id_t (const timer_id_t &)=delete
timer_id_toperator= (const timer_id_t &)=delete
 timer_id_t (timer_id_t &&) noexcept=default
timer_id_toperator= (timer_id_t &&) noexcept=default
bool is_active () const noexcept
 Is message delivery still in progress? More...
void release () noexcept
 Revoke the message and release the timer. More...
void revoke () noexcept
 Revoke the message and release the timer. More...

Private Member Functions

 timer_id_t (::so_5::intrusive_ptr_t< details::envelope_t > envelope, ::so_5::timer_id_t actual_id)

Private Attributes

::so_5::intrusive_ptr_t< details::envelope_tm_envelope
 The envelope that was sent. More...
::so_5::timer_id_t m_actual_id
 Timer ID for the envelope. More...


struct ::so_5::extra::revocable_timer::impl::timer_id_maker_t
void swap (timer_id_t &a, timer_id_t &b) noexcept

Detailed Description

The ID of revocable timer message/signal.

This type plays the same role as so_5::timer_id_t. But provide guaranteed revocation of delayed/periodic message/signal.

There are several implementations of send_delayed() and send_periodic() functions in so_5::extra::revocable_timer namespace. They all return instances of timer_id_t.

An instance of timer_id_t returned from send_delayed/send_periodic need to be store somewhere. Otherwise the timer message will be revoked just after completion of send_delayed/send_periodic function. It is because the destructor of timer_id_t will be called and that destructor revokes the timer message.

An instance of timer_id_t can be used for revocation of a timer message. Revocation can be performed by two ways:

  1. Destructor of timer_id_t automatically revokes the timer message.
  2. Method timer_id_t::release() or timer_id_t::revoke() is called by an user.

For example:

namespace timer_ns = so_5::extra::revocable_timer;
void demo(so_5::mchain_t work_queue) {
// Send a delayed demand to work queue and store the ID returned.
auto id = timer_ns::send_delayed<flush_data>(work_queue, 10s, ...);
... // Do some work.
// Our previous message should be revoked if it is not delivered yet.
// Message will be automatically revoked here because ID is destroyed
// on leaving the scope.
The timer_id_t is Movable, not Copyable.
This is not a thread-safe class. It means that it is dangerous to call methods of that class (like revoke() or is_active()) from different threads at the same time.

Definition at line 106 of file pub.hpp.

Constructor & Destructor Documentation

◆ timer_id_t() [1/4]

so_5::extra::revocable_timer::timer_id_t::timer_id_t ( ::so_5::intrusive_ptr_t< details::envelope_t envelope,
::so_5::timer_id_t  actual_id 

Definition at line 120 of file pub.hpp.

◆ timer_id_t() [2/4]

so_5::extra::revocable_timer::timer_id_t::timer_id_t ( )

◆ ~timer_id_t()

so_5::extra::revocable_timer::timer_id_t::~timer_id_t ( )
The destructor automatically revokes the message if it is not delivered yet.

Definition at line 133 of file pub.hpp.

◆ timer_id_t() [3/4]

so_5::extra::revocable_timer::timer_id_t::timer_id_t ( const timer_id_t )

◆ timer_id_t() [4/4]

so_5::extra::revocable_timer::timer_id_t::timer_id_t ( timer_id_t &&  )

Member Function Documentation

◆ is_active()

bool so_5::extra::revocable_timer::timer_id_t::is_active ( ) const

Is message delivery still in progress?

Please take care when using this method. Message delivery in SObjectizer is asynchronous operation. It means that you can receve true from is_active() but this value will already be obsolete because the message can be delivered just before return from is_active(). The return value of is_active() can be useful in that context:
namespace timer_ns = so_5::extra::revocable_timer;
void demo(so_5::mchain_t work_queue) {
auto id = timer_ns::send_delayed(work_queue, 10s, ...);
... // Do some work.
... // Do some more work.
if(id.is_active()) {
// No previous calls to revoke().

Definition at line 180 of file pub.hpp.

◆ operator=() [1/2]

timer_id_t& so_5::extra::revocable_timer::timer_id_t::operator= ( const timer_id_t )

◆ operator=() [2/2]

timer_id_t& so_5::extra::revocable_timer::timer_id_t::operator= ( timer_id_t &&  )

◆ release()

void so_5::extra::revocable_timer::timer_id_t::release ( )

Revoke the message and release the timer.

It is safe to call release() for already revoked message.

Definition at line 191 of file pub.hpp.

◆ revoke()

void so_5::extra::revocable_timer::timer_id_t::revoke ( )

Revoke the message and release the timer.

Just a synonym for release() method.

Definition at line 207 of file pub.hpp.

Friends And Related Function Documentation

◆ ::so_5::extra::revocable_timer::impl::timer_id_maker_t

Definition at line 108 of file pub.hpp.

◆ swap

void swap ( timer_id_t a,
timer_id_t b 

Definition at line 147 of file pub.hpp.

Member Data Documentation

◆ m_actual_id

::so_5::timer_id_t so_5::extra::revocable_timer::timer_id_t::m_actual_id

Timer ID for the envelope.

Definition at line 118 of file pub.hpp.

◆ m_envelope

::so_5::intrusive_ptr_t< details::envelope_t > so_5::extra::revocable_timer::timer_id_t::m_envelope

The envelope that was sent.

Can be nullptr if default constructor was used.

Definition at line 115 of file pub.hpp.

The documentation for this class was generated from the following file: