Hades - A wrapper for NMAP written in Elixir 10 Killer Elixir Tips —#10

Schoolbus - Manage one or more PubSub instances using the Elixir registry

https://github.com/rupurt/schoolbus

Start the bus

iex(1)> {:ok, _bus} = Schoolbus.start_link([])
{:ok, #PID<0.212.0>}

Register a topic

iex(2)> Schoolbus.register(:games)
:ok

Register a namespaced topic

iex(3)> Schoolbus.register({:songs, :diplo})
:ok
iex(4)> Schoolbus.register({:songs, :tiesto})
:ok

Subscribe to a registered topic

iex(3)> Schoolbus.subscribers()
[]
iex(4)> Schoolbus.subscribe(:games)
{:ok, [:games]}
iex(5)> self()
#PID<0.208.0>
iex(6)> Schoolbus.subscribers()
[games: #PID<0.208.0>]

Subscribe to all topics within a namespace

iex(7)> Schoolbus.subscribers()
[games: #PID<0.208.0>]
iex(8)> Schoolbus.subscribe({:songs, "*"})
{:ok, [songs: :diplo, songs: :tiesto]}
iex(9)> self()
#PID<0.208.0>
iex(10)> Schoolbus.subscribers()
[
  {{:songs, :tiesto}, #PID<0.208.0>},
  {{:songs, :diplo}, #PID<0.208.0>},
  {:games, #PID<0.208.0>}
]

Broadcast a topic to all subscribers

iex(11)> flush
:ok
iex(12)> Schoolbus.broadcast(:games, :uno)
:ok
iex(13)> flush
:uno
:ok

ElixirWeekly: The Elixir Community Newsletter, covering community news you easily miss, shared on ElixirStatus and the web, in one email every Thursday.