View Source Rivet.Utils.Interval2 (rivet_utils v2.0.5)

Make sure only one of a method callback is ever running.

Interval and last run time are stored in state. You can adjust interval on the fly, but it'll kick in on second iteration after this one because the next one is already queued.

Contributor: Brandon Gillespie

Usage:

use Interval2, tick: 1_000
# or use Interval2, ... options

In process startup:

  interval_start(state)

Then later:

def interval(state) do
  # do a thing
  {:ok, state}
end

Supported options:

tick: integer # REQUIRED error_logger: {M, f} # default: {Logger, :error} # two-arg arity callback: :interval # function name to call