Gtimer (gtimer v0.2.0)
A small library which provides a global timer facility in Elixir (or Erlang).
Example:
iex> timer_ref = Gtimer.new_timer(timeout,options \ [])
Starts a new timer running for timeout
millseconds, returns a "timer reference".
iex> Gtimer.cancel_timer(timer_ref)
Cancels a running timer.
If a running timer is not cancelled when the timer expires a
timeout_action
function (defined as an option)
will be called with the process identifier of the process that created the timer
as a single argument. If the timeout_action is not a function of arity 1, then the
default action of logging an informative warning message, will be taken.
Timer management is done in a separate process. Inside the process timers are stored in a priority queue, and using a map, which affords logarithmic worst-case time complexity for both function calls (in terms of the number of timers running).
Example:
iex> timer_ref = Gtimer.new_timer(1000,fn pid -> Process.exit(pid,:because) end)
This will start a new timer which when it expires kills the process which invoked
the call to new_timer
.
Summary
Functions
Cancels a running timer.
Returns a specification to start this module under a supervisor.
Returns expired timers.
Starts a new timer running for timeout
millseconds, returns a "timer reference".
If a running timer is not cancelled when the timer expires the timeout_action function
will be called with the process identifier of the process that created the timer as
a single argument. Options may define a {timeout_action
,fun}
which is the action taken when a timer expires, or {log_level
,level}
which determines the Log level for timer expire messages.
Functions
cancel_timer(time_ref)
Cancels a running timer.
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
expired_timers()
Returns expired timers.
new_timer(timeout, info, options \\ [])
Starts a new timer running for timeout
millseconds, returns a "timer reference".
If a running timer is not cancelled when the timer expires the timeout_action function
will be called with the process identifier of the process that created the timer as
a single argument. Options may define a {timeout_action
,fun}
which is the action taken when a timer expires, or {log_level
,level}
which determines the Log level for timer expire messages.