{:ok,_} =Registry.start_link(keys: :duplicate, name: Registry.DispatcherTest){:ok,_} =Registry.register(Registry.DispatcherTest,"hello", {IO, :inspect})Registry.dispatch(Registry.DispatcherTest,"hello",fn entries ->for {pid, {module, function}} <- entries, do: apply(module, function, [pid])end)# Prints #PID<...> where the PID is for the process that called register/3 above
Pubsub
Registries can also be used to implement a local, non-distributed, scalable PubSub by relying on the dispatch/3
Can also use Genserver.call/2 with the name to send direct message
defspeaker_layout(cname, maxResolutionUid) do name = {:via,Registry, {EventGenServer, cname}}GenServer.call(name, {:speaker_layout, maxResolutionUid})end