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

Requires Elixir 1.9+ as it depends on to list subscribers

Start the bus

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

Register a topic

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

Register a namespaced topic

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

Subscribe to a registered topic

iex(3)> Schoolbus.subscribers()
iex(4)> Schoolbus.subscribe(:games)
{:ok, [:games]}
iex(5)> self()
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()
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
iex(12)> Schoolbus.broadcast(:games, :uno)
iex(13)> flush