gen_timer v1.0.0 GenTimer behaviour View Source

Extends GenServer to give a timer functionality.

There is a small folder of examples in this repo to guide you.

Callbacks

Supports the same callbacks as GenServer. The only considerations are:

There Is Required State For init/1

The state returned by GenServer.init/1 must include the required keys shown in valid_state/0, but then you can add any other state you please.

Repeated Funtion Callback

The callback repeated_function/1 is where you choose what is done each iteration. It will use the current state as the argument and will use the returned state as the state of the GenServer going forward.

Link to this section Summary

Callbacks

This is where you choose what is done each iteration.

Link to this section Types

Link to this type

valid_state()

View Source
valid_state() :: %{
  milli: pos_integer(),
  times: pos_integer() | :infinite,
  last_return: any()
}

Link to this section Functions

Link to this function

abcast(nodes, name, request)

View Source

See GenServer.abcast/3.

Link to this function

call(server, request, timeout)

View Source

See GenServer.call/3.

See GenServer.cast/2.

Link to this function

multi_call(nodes, name, request, timeout)

View Source

See GenServer.multi_call/4.

See GenServer.reply/2.

Link to this function

start(module, args, options)

View Source

Use exactly the same as GenServer.start/3.

Only difference is that it will send a message to the process to start the timer.

Link to this function

start_link(module, args, options)

View Source
start_link(atom(), any(), GenServer.options()) :: GenServer.on_start()

Use exactly the same as GenServer.start_link/3.

Only difference is that it will send a message to the process to start the timer.

Link to this function

stop(server, reason, timeout)

View Source

See GenServer.stop/3.

Link to this section Callbacks

Link to this callback

repeated_function(state)

View Source
repeated_function(state :: valid_state()) :: valid_state()

This is where you choose what is done each iteration.

It will use the current state as the argument and will use the returned state as the state of the GenServer going forward.