@@ -171,6 +171,9 @@ defmodule Phoenix.PubSub do
171171 * `:broadcast_pool_size` - number of pubsub partitions used for broadcasting messages
172172 (defaults to `:pool_size`). This option is used during pool size migrations to ensure
173173 no messages are lost. See the "Safe Pool Size Migration" section in the module documentation.
174+ * `:dispatcher` - the default dispatcher module for broadcasts
175+ (defaults to `Phoenix.PubSub`). Can be overridden per-call by
176+ passing a dispatcher to `broadcast/4` and friends.
174177
175178 """
176179 @ spec child_spec ( keyword ) :: Supervisor . child_spec ( )
@@ -249,9 +252,10 @@ defmodule Phoenix.PubSub do
249252 See the "Custom dispatching" section in the module documentation.
250253 """
251254 @ spec broadcast ( t , topic , message , dispatcher ) :: :ok | { :error , term }
252- def broadcast ( pubsub , topic , message , dispatcher \\ __MODULE__ )
255+ def broadcast ( pubsub , topic , message , dispatcher \\ nil )
253256 when is_atom ( pubsub ) and is_binary ( topic ) and is_atom ( dispatcher ) do
254- { :ok , { adapter , name } } = Registry . meta ( pubsub , :pubsub )
257+ { :ok , { adapter , name , default_dispatcher } } = Registry . meta ( pubsub , :pubsub )
258+ dispatcher = dispatcher || default_dispatcher
255259
256260 with :ok <- adapter . broadcast ( name , topic , message , dispatcher ) do
257261 dispatch ( pubsub , :none , topic , message , dispatcher )
@@ -273,9 +277,10 @@ defmodule Phoenix.PubSub do
273277 See the "Custom dispatching" section in the module documentation.
274278 """
275279 @ spec broadcast_from ( t , pid , topic , message , dispatcher ) :: :ok | { :error , term }
276- def broadcast_from ( pubsub , from , topic , message , dispatcher \\ __MODULE__ )
280+ def broadcast_from ( pubsub , from , topic , message , dispatcher \\ nil )
277281 when is_atom ( pubsub ) and is_pid ( from ) and is_binary ( topic ) and is_atom ( dispatcher ) do
278- { :ok , { adapter , name } } = Registry . meta ( pubsub , :pubsub )
282+ { :ok , { adapter , name , default_dispatcher } } = Registry . meta ( pubsub , :pubsub )
283+ dispatcher = dispatcher || default_dispatcher
279284
280285 with :ok <- adapter . broadcast ( name , topic , message , dispatcher ) do
281286 dispatch ( pubsub , from , topic , message , dispatcher )
@@ -293,9 +298,10 @@ defmodule Phoenix.PubSub do
293298 See the "Custom dispatching" section in the module documentation.
294299 """
295300 @ spec local_broadcast ( t , topic , message , dispatcher ) :: :ok
296- def local_broadcast ( pubsub , topic , message , dispatcher \\ __MODULE__ )
301+ def local_broadcast ( pubsub , topic , message , dispatcher \\ nil )
297302 when is_atom ( pubsub ) and is_binary ( topic ) and is_atom ( dispatcher ) do
298- dispatch ( pubsub , :none , topic , message , dispatcher )
303+ { :ok , { _adapter , _name , default_dispatcher } } = Registry . meta ( pubsub , :pubsub )
304+ dispatch ( pubsub , :none , topic , message , dispatcher || default_dispatcher )
299305 end
300306
301307 @ doc """
@@ -313,9 +319,10 @@ defmodule Phoenix.PubSub do
313319 See the "Custom dispatching" section in the module documentation.
314320 """
315321 @ spec local_broadcast_from ( t , pid , topic , message , dispatcher ) :: :ok
316- def local_broadcast_from ( pubsub , from , topic , message , dispatcher \\ __MODULE__ )
322+ def local_broadcast_from ( pubsub , from , topic , message , dispatcher \\ nil )
317323 when is_atom ( pubsub ) and is_pid ( from ) and is_binary ( topic ) and is_atom ( dispatcher ) do
318- dispatch ( pubsub , from , topic , message , dispatcher )
324+ { :ok , { _adapter , _name , default_dispatcher } } = Registry . meta ( pubsub , :pubsub )
325+ dispatch ( pubsub , from , topic , message , dispatcher || default_dispatcher )
319326 end
320327
321328 @ doc """
@@ -333,17 +340,17 @@ defmodule Phoenix.PubSub do
333340 See the "Custom dispatching" section in the module documentation.
334341 """
335342 @ spec direct_broadcast ( node_name , t , topic , message , dispatcher ) :: :ok | { :error , term }
336- def direct_broadcast ( node_name , pubsub , topic , message , dispatcher \\ __MODULE__ )
343+ def direct_broadcast ( node_name , pubsub , topic , message , dispatcher \\ nil )
337344 when is_atom ( pubsub ) and is_binary ( topic ) and is_atom ( dispatcher ) do
338- { :ok , { adapter , name } } = Registry . meta ( pubsub , :pubsub )
339- adapter . direct_broadcast ( name , node_name , topic , message , dispatcher )
345+ { :ok , { adapter , name , default_dispatcher } } = Registry . meta ( pubsub , :pubsub )
346+ adapter . direct_broadcast ( name , node_name , topic , message , dispatcher || default_dispatcher )
340347 end
341348
342349 @ doc """
343350 Raising version of `broadcast/4`.
344351 """
345352 @ spec broadcast! ( t , topic , message , dispatcher ) :: :ok
346- def broadcast! ( pubsub , topic , message , dispatcher \\ __MODULE__ ) do
353+ def broadcast! ( pubsub , topic , message , dispatcher \\ nil ) do
347354 case broadcast ( pubsub , topic , message , dispatcher ) do
348355 :ok -> :ok
349356 { :error , error } -> raise BroadcastError , "broadcast failed: #{ inspect ( error ) } "
@@ -354,7 +361,7 @@ defmodule Phoenix.PubSub do
354361 Raising version of `broadcast_from/5`.
355362 """
356363 @ spec broadcast_from! ( t , pid , topic , message , dispatcher ) :: :ok
357- def broadcast_from! ( pubsub , from , topic , message , dispatcher \\ __MODULE__ ) do
364+ def broadcast_from! ( pubsub , from , topic , message , dispatcher \\ nil ) do
358365 case broadcast_from ( pubsub , from , topic , message , dispatcher ) do
359366 :ok -> :ok
360367 { :error , error } -> raise BroadcastError , "broadcast failed: #{ inspect ( error ) } "
@@ -365,7 +372,7 @@ defmodule Phoenix.PubSub do
365372 Raising version of `direct_broadcast/5`.
366373 """
367374 @ spec direct_broadcast! ( node_name , t , topic , message , dispatcher ) :: :ok
368- def direct_broadcast! ( node_name , pubsub , topic , message , dispatcher \\ __MODULE__ ) do
375+ def direct_broadcast! ( node_name , pubsub , topic , message , dispatcher \\ nil ) do
369376 case direct_broadcast ( node_name , pubsub , topic , message , dispatcher ) do
370377 :ok -> :ok
371378 { :error , error } -> raise BroadcastError , "broadcast failed: #{ inspect ( error ) } "
@@ -377,7 +384,7 @@ defmodule Phoenix.PubSub do
377384 """
378385 @ spec node_name ( t ) :: node_name
379386 def node_name ( pubsub ) do
380- { :ok , { adapter , name } } = Registry . meta ( pubsub , :pubsub )
387+ { :ok , { adapter , name , _dispatcher } } = Registry . meta ( pubsub , :pubsub )
381388 adapter . node_name ( name )
382389 end
383390
0 commit comments