Dead simple Automatic Request Repeat implementation for independent messages.
Local party sends messages by providing an mfa or a fun/0 to ARQ.start/2
.
Upon receipt of message, remote party can acknowledge the message (and stop its repeat) by calling ARQ.stop/1
or sending :stop
to the requestor process.
{:ok, supervisor} = ARQ.start_link()
receiver =
spawn(fn ->
receive do
{sender, msg} ->
IO.puts "Received #{inspect msg} from #{inspect sender}, telling it to stop."
ARQ.stop(sender)
end
end)
ARQ.start(fn -> send(receiver, {self(), :hi}) end, supervisor)
If available in Hex, the package can be installed
by adding arq
to your list of dependencies in mix.exs
:
def deps do
[
{:arq, "~> 0.3.1"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/arq.