GrassHopper behaviour (grass_hopper v0.1.0)

GrassHopper is a tiny abstraction over GenServer, that helps building dynamically scheduled recursive processes. It allows to efficiently jump along timestamps and perform user defined actions. Think of a librarian going through the list of borrowed books and calling the borrowers as their leases reach the due date.

User of GrassHopper needs to implement two callbacks:

  • next is called to compute the next timestamp (NaiveDateTime) or nil which will cause the process to wait indefinitely or max_timeout
  • perform: called to perform the operation on a given interval

Link to this section Summary

Link to this section Types

Specs

state() :: %{opts: Keyword.t(), from: NaiveDateTime.t(), to: NaiveDateTime.t()}

Link to this section Callbacks

Specs

next(state()) :: NaiveDateTime.t() | nil

Specs

perform(state()) :: any()

Link to this section Functions

Specs

refresh(atom()) :: any()
Link to this function

trim_timeout(timeout, opts \\ [])

Specs

trim_timeout(timeout(), Keyword.t()) :: timeout()