ExTicker

Simple Elixir ticker.

Basic usage

Defining your periodical worker:

defmodule MyWorker do
  # Options:
  # - interval  -> interval (ms), default 1000
  # - do        -> function to trigger, default :work
  use ExTicker, interval: 5000, do: :work

  def work() do
    # .. do some stuff ...
  end
end

You create it with:

MyWorker.start_link([])

With this #start_link function, MyWorker could be started by your supervisor:

children = [
 {MyWorker, []}
]

opts = [strategy: :one_for_one, name: MySupervisor]
Supervisor.start_link(children, opts)

After creation, you can start / stop it with:

MyWorker.start()
# begin to do some thing periodically
MyWorker.stop()
# stopped
MyWorker.start()
# restarted ...

Installation

If available in Hex, the package can be installed by adding exticker to your list of dependencies in mix.exs:

def deps do
  [
    {:exticker, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exticker.