This class provides a thread‐safe event scheduler. scheduleEvent schedules a non‐recurring event, returning a handle of type TimerEventScheduler::Handle, which can be used to cancel the scheduled event by invoking cancelEvent. Similarly, startClock schedules a recurring event, returning a handle of type TimerEventScheduler::Handle, which can be used to cancel the clock by invoking cancelClock. cancelAllEvents cancels all the registered events and cancelAllClocks cancels all the registered clocks. The callbacks are processed by a separate thread (called dispatcher thread). By default the callbacks are executed in the dispatcher thread, but this behavior can be altered by providing a dispatcher functor at the creation time (see the section "The dispatcher thread and the dispatcher functor"). start must be invoked to start dispatching the callbacks. stop stops the dispatching of the callbacks without removing the pending events.

Synopsis

Declared in <bdlmt_timereventscheduler.h>

class TimerEventScheduler;

Type Aliases

Name

Description

Dispatcher

Defines a type alias for the dispatcher functor type.

EventKey

Defines a type alias for a user‐supplied key for identifying events.

Handle

Defines a type alias for a handle that identifies a scheduled clock or event.

Enums

Name

Description

Unnamed enum

Invalid handle constants.

Member Functions

Name

Description

TimerEventScheduler [constructor]

Constructors

~TimerEventScheduler [destructor]

Stop this scheduler, discard all the unprocessed events and destroy this object.

cancelAllClocks

Cancel all clocks. If the optionally specified wait is true, then ensure that any clock event still in this scheduler is either cancelled or has been dispatched before this call returns. If this method is being invoked from the dispatcher thread, then the wait is ignored to avoid deadlock.

cancelAllEvents

Cancel all the events. If the optionally specified wait is true, then ensure any event still in this scheduler is either cancelled or has been dispatched before this call returns. If this method is being invoked from the dispatcher thread then the wait is ignored to avoid deadlock.

cancelClock

Cancel the clock having the specified handle. If the optionally specified wait is true, then ensure that any scheduled event for the clock having handle is either cancelled or has been dispatched before this call returns. Return 0 on success, and a non‐zero value if the handle is invalid. If this method is being invoked from the dispatcher thread, then the wait is ignored to avoid deadlock.

cancelEvent

cancelEvent overloads

clockType

Return the value of the clock type that this object was created with.

nextPendingEventTime

Return the earliest scheduled starting time of the pending events and clocks registered with this scheduler. If there are no pending events or clocks, return INT64_MAX microseconds.

now

Return the current epoch time, an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see []Clock‐Types)).

numClocks

Return a snapshot of the number of registered clocks with this scheduler.

numEvents

Return a snapshot of the number of pending events and events being dispatched in this scheduler.

rescheduleEvent

rescheduleEvent overloads

scheduleEvent

Schedule the specified callback to be dispatched at the specified time. On success, return a handle that can be used to cancel the callback (by invoking cancelEvent), or return e_INVALID_HANDLE if scheduling this event would exceed the maximum number of scheduled events for this object (see constructor). Optionally specify key to uniquely identify the event. The time is an absolute time represented as an interval from some epoch, which is detemined by the clock indicated at construction (see []Clock‐Types)).

start

start overloads

startClock

Schedule a recurring event that invokes the specified callback at every specified interval, starting at the optionally specified startTime. On success, return a handle that can be use to cancel the clock (by invoking cancelClock), or return e_INVALID_HANDLE if scheduling this event would exceed the maximum number of scheduled events for this object (see constructor). If no start time is specified, it is assumed to be the interval time from now. The startTime is an absolute time represented as an interval from some epoch, which is detemined by the clock indicated at construction (see []Clock‐Types)).

stop

End the dispatching of events on this scheduler (but do not remove any pending events), and wait for any (one) currently executing event to complete. If the scheduler is already stopped then this method has no effect. This scheduler can be restarted by invoking start. The behavior is undefined if this method is invoked from the dispatcher thread.

operator BloombergLP::bslmf::NestedTraitDeclaration<TimerEventScheduler, UsesBslmaAllocator>

Declare that this type uses a bslma allocator.

Friends

Name

Description

BloombergLP::bdlmt::TimerEventSchedulerTestTimeSource

This class provides a means to change the clock that is used by a given event‐scheduler to determine when events should be triggered. Constructing a TimerEventSchedulerTestTimeSource alters the behavior of the supplied event‐scheduler. After a test time‐source is created, the underlying scheduler will run events according to a discrete timeline, whose successive values are determined by calls to advanceTime on the test time‐source, and can be retrieved by calling now on that test time‐source. Note that the "system‐time" held by a test time‐source does not correspond to the current system time. Test writers must use caution when scheduling absolute‐time events so that they are scheduled relative to the test time‐source's value for now.

BloombergLP::bdlmt::TimerEventSchedulerDispatcher

Dispatcher functor type for TimerEventScheduler.

Created with MrDocs