micro_timer v0.1.0 MicroTimer View Source
A timer module with microsecond resolution.
Link to this section Summary
Functions
Invokes the given executable
after timeout
microseconds with the list of
arguments args
Invokes the given executable
repeatedly every timeout
microseconds with the list of
arguments args
Cancel a timer pid
created by apply_after/2
, apply_after/3
, apply_every/2
or apply_every/3
Send message
to pid
after timeout
microseconds
Send message
to pid
every timeout
microseconds
Suspend the current process for the given timeout
and then returns :ok
Link to this section Types
Link to this section Functions
apply_after(non_neg_integer(), executable(), [any()]) :: pid()
Invokes the given executable
after timeout
microseconds with the list of
arguments args
.
executable
can either be the tuple {Module, :function}
, an anonymous function
or a function capture.
Returns the pid
of the timer.
See also cancel_timer/1
.
Examples
MicroTimer.apply_after(250, {Module. :function}, [])
MicroTimer.apply_after(250, fn a -> a + 1 end, [1])
iex> pid = MicroTimer.apply_after(250, fn arg -> arg end, [1])
iex> is_pid(pid)
true
apply_every(non_neg_integer(), executable(), [any()]) :: pid()
Invokes the given executable
repeatedly every timeout
microseconds with the list of
arguments args
.
executable
can either be the tuple {Module, :function}
, an anonymous function
or a function capture.
Returns the pid
of the timer.
See also cancel_timer/1
.
Examples
MicroTimer.apply_every(250, {Module. :function}, [])
MicroTimer.apply_every(250, fn a -> a + 1 end, [1])
iex> pid = MicroTimer.apply_every(250, fn arg -> arg end, [1])
iex> is_pid(pid)
true
Cancel a timer pid
created by apply_after/2
, apply_after/3
, apply_every/2
or apply_every/3
Always returns true
Examples
timer = MicroTimer.apply_every(250, {Module. :function}, [])
MicroTimer.cancel_timer(timer)
iex> pid = MicroTimer.apply_every(250, fn arg -> arg end, [1])
iex> MicroTimer.cancel_timer(pid)
iex> Process.alive?(pid)
false
send_after(non_neg_integer(), any(), pid()) :: pid()
Send message
to pid
after timeout
microseconds.
If pid
is left empty, the message
is sent to self()
.
Returns the pid
of the timer.
See also cancel_timer/1
.
Examples
MicroTimer.send_after(250, :msg)
MicroTimer.send_after(250, "msg", self())
iex> pid = MicroTimer.send_after(250, :msg)
iex> is_pid(pid)
true
send_every(non_neg_integer(), any(), pid()) :: pid()
Send message
to pid
every timeout
microseconds.
If pid
is left empty, the message
is sent to self()
.
Returns the pid
of the timer.
See also cancel_timer/1
.
Examples
MicroTimer.send_every(250, :msg)
MicroTimer.send_every(250, "msg", self())
iex> pid = MicroTimer.send_every(250, :msg)
iex> is_pid(pid)
true