The tiny framework to simplify work with events, based on GenStage
Antenna
is a mixture of Phoenix.PubSub
and :gen_event
functionality
with some batteries included.
It implements back-pressure on top of GenStage
, is fully conformant with
OTP Design Principles. and
is distributed out of the box.
Antenna
supports both asynchronous and synchronous events. While the most preferrable way
would be to stay fully async with Antenna.event/3
, one still might propagate the event
synchronously with Antenna.sync_event/3
and collect all the responses from all the handlers.
One can have as many isolated Antenna
s as necessary, distinguished by Antenna.t:id/0
.
The workflow looks like shown below.
┌───────────────┐
│ │ Antenna.event(AntID, :tag1, %{foo: 42})
│ Broadcaster │───────────────────────────────────────────────
│ │
└───────────────┘
──/──
────── / ─────
────── / ──────
────── / ─────
──── / ───
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│ │ │ │ │ │
│ Consumer@node1 │ │ Consumer@node1 │ … │ Consumer@nodeN │
│ │ │ │ │ │
└────────────────┘ └────────────────┘ └────────────────┘
· · ·
/ \ / \ / \
/ \ / \ / \
· mine? · · mine? · · mine? ·
\ / \ / \ /
\ / \ / \ /
· · ·
│ │ │
│ │ │
───── │ ─────
│
│
┌──────────────┐
│ │ if (match?), do: call_handlers(event)
│ matchers │───────────────────────────────────────────────────
│ │
└──────────────┘
The consumer of this library is supposed to declare one or more matchers, subscribing to one
or more channels, and then call Antenna.event/2
to propagate the event.
def deps do
[
{:antenna, "~> 0.2"}
6000
]
end
Sure, it is.