module Timer: Timertype t
type event
type interval =
| |
INone |
(* | No repetition of events | *) |
| |
INormal of |
|||
| |
IRandom of |
val create : ?min_size:int -> ?tick_unit:Time.Span.t -> unit -> tcreate ?min_size ?tick_unit () creates a new timer. It will poll
for new events every tick_unit seconds, which must be greater than
zero. The minimum size of the heap used by the timer is min_size.Invalid_argument if tick_unit < 0.0min_size : default = 1000tick_unit : default = 0.1val deactivate : t -> unitdeactivate timer deactives a timer. At most one scheduled event
will get executed after this function returns.val add : t ->
(event -> Time.t -> unit) ->
?randomize:float -> ?interval:Time.Span.t -> Time.Span.t -> eventadd timer handler ?randomize ?interval spanFailure if timer is deactivated.Invalid_argument if interval is a time span <= 0.0.Invalid_argument if maximum random ratio not within [0.0, 1.0].handler will be executed span seconds at the earliest
after this function returns, and it gets its associated event as
argument (useful for letting interval timers remove themselves)
and the time at which the timer thread woke up.
NOTE: the handler must not allow any exceptions to escape. span
must be greater than zero. If the same handler is used in multiple
timers, then the handler must be reentrant. The handler must not
block, and should return as quickly as possible, eventually passing
off work to other threads if handling an event would take too long.
An interval can be specified to keep rescheduling the event.
interval can be randomized (e.g. for proteanism): the float
specifies the maximum ratio with which interval will be multiplied
and added to itself, and must be in the range [0.0, 1.0].
randomize : default = noneinterval : default = noneval add_abs : t ->
(event -> Time.t -> unit) ->
?randomize:float -> ?interval:Time.Span.t -> Time.t -> eventadd_abs timer handler ?randomize ?interval time same as Timer.add, but
takes an absolute time time for scheduling the event rather than
a span. This prevents a time-induced race condition if there is
a long time between the internal reading of the current time and
the scheduling of the event, which would artificially delay event
execution.val remove : event -> unitremove event removes event from its associated timer.
NOTE: there is no guarantee that the event will not happen anymore
if this function returns. The timer thread may be about to start
the callback, which leads to an inevitable race condition here.
Users should be aware of this situation and make sure to handle
it correctly.
Raises Failure if timer is deactivated.
val reschedule : event ->
?randomize:float -> ?interval:Time.Span.t -> Time.Span.t -> unitreschedule event ?randomize ?interval span reschedules event
to start by time span span later than originally scheduled, and
change its interval behaviour as described for Timer.add.Failure if timer is deactivated.Invalid_argument if interval is a time span <= 0.0.Invalid_argument if maximum random ratio not within [0.0, 1.0].Failure if event was not already scheduled.val get_timer : event -> tget_timer eventevent.val get_event_time : event -> Time.tget_event_time eventevent is scheduled
to be run.val get_event_interval : event -> intervalget_event_interval eventevent.val is_activated : t -> boolis_activated timertrue iff timer is activated.