Time-based event creation

yasmine offers time-based event creation. With this feature, it is possible to fire events after a period of time or fire events on a scheduled time, calling the overloaded method create_event_creation_request.

The event creator maintains a queue of events that are scheduled to be fired and is woken up every time an event should be fired.

When an event is fired the queue of scheduled events is queried to see if any events' timers have expired. If expired they will then be fired, otherwise the event creator waits for the next timer to expire.

The feature is provided by the class timed_event_creator.

Example code

sxy::timed_event_creator event_creator( *_state_machine );
event_creator.start();
sxy::event_id l_event = 1;
event_creator.create_event_creation_request( std::chrono::milliseconds( 5000 ), sxy::event_impl::create( l_event ) );

To create a timed-based event creation object, we need to pass the reference to the state machine as parameter to the constructor of the class timed_event_creator.

Next, the event creator must be started. Then, the object can be used to create events. The parameters are the time when we want the event to be fired, the event’s ID, and the event’s parameters.

The event creator will fire the event at the specified time (if the state machine is running at that moment).

Creating timed events often requires that some kind of "cookie" is passed as a parameter along with the timeout event. This is especially true for timeout events. If a timeout cannot be canceled (because the event was just fired) a timeout event may arrive too late. This is particularly bad if this happnes in a situation where that kind of timeout might occur/is expected.
In order to deal with this, some kind of information that links the timeout to a specific process that can timeout, should be passed along with the timeout event. This can be as simple as a counter. Then when a timeout occurs you can check if the timeout belongs to your process or maybe to an older one and thus needs to be ignored.
This check can be performed in the guard of the timeout transition.