Packages

Compatibility layer for pg and pg2

Current section

Files

Jump to
uni_pg lib uni_pg.ex
Raw

lib/uni_pg.ex

defmodule UniPg do
@type scope :: atom()
@type group :: any()
@callback join(scope, group, list(pid())) :: :ok
@callback leave(scope, group, list(pid())) :: :ok
@callback get_local_members(scope, group) :: list(pid())
@callback get_members(scope, group) :: list(pid())
@callback which_groups(scope) :: list(group())
impl = if Code.ensure_loaded?(:pg), do: UniPg.Pg, else: UniPg.Pg2
defdelegate join(scope, group, pids), to: impl
defdelegate leave(scope, group, pids), to: impl
defdelegate get_local_members(scope, group), to: impl
defdelegate get_members(scope, group), to: impl
defdelegate which_groups(scope), to: impl
end