GenLoop

This library is an adaptation of awesome Ulf Wiger's erlang library :plain_fsm for Elixir. It reuses as :plain_fsm code as possible, but adds some features :

This is still a work in progress, notably the documentation must be completed.

Installation

The package can be installed by adding gen_loop to your list of dependencies in mix.exs:

def deps do
  [
    {:gen_loop, "~> 1.0"},
  ]
end

As of version 1.0.0, plain_fsm is a normal dependency pulled from hex.pm.

Why ?

This library is a direct concurrent to GenServer or :gen_statem : it provides selective receive and more freedom but makes it easier to shoot yourself in the foot.

More info in plain_fsm rationale.

How To ?

This section is to be polished, but basically :

 use GenLoop, get_state: :all

Have a look at loop_example.ex.

Alternative

GenLoop is designed for communicating processes : servers, FSMs, etc. Have a look at the Task module if you just want to supervise autonomous processes.

GenLoop is not a replacement for GenServer : if your have only one loop in your module with a "catch all messages" clause, you woud better use GenServer instead of GenLoop.

You may also use :gen_statem as a good replacement to selective receives.