Packages
Typed distributed messaging for Gleam on the BEAM.
Retired package: Deprecated - The project needs to be redesigned around a much smaller and clearer core.
Current section
Files
Jump to
Current section
Files
src/distribute@groups.erl
-module(distribute@groups).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/distribute/groups.gleam").
-export([join/2, leave/2, members/1, broadcast/2]).
-export_type([group_error/0, dynamic_/0, pid_/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type group_error() :: {group_failed, binary()}.
-type dynamic_() :: any().
-type pid_() :: any().
-file("src/distribute/groups.gleam", 39).
?DOC(" Join a process to a named group.\n").
-spec join(binary(), pid_()) -> {ok, nil} | {error, group_error()}.
join(Group, Pid) ->
Res = groups_ffi:join(Group, Pid),
case groups_ffi:is_ok_atom(Res) of
true ->
{ok, nil};
false ->
{error, {group_failed, groups_ffi:get_error_reason(Res)}}
end.
-file("src/distribute/groups.gleam", 48).
?DOC(" Remove a process from a named group.\n").
-spec leave(binary(), pid_()) -> {ok, nil} | {error, group_error()}.
leave(Group, Pid) ->
Res = groups_ffi:leave(Group, Pid),
case groups_ffi:is_ok_atom(Res) of
true ->
{ok, nil};
false ->
{error, {group_failed, groups_ffi:get_error_reason(Res)}}
end.
-file("src/distribute/groups.gleam", 57).
?DOC(" Get the list of member pids in a group.\n").
-spec members(binary()) -> list(pid_()).
members(Group) ->
Res = groups_ffi:members(Group),
groups_ffi:unwrap_members(Res).
-file("src/distribute/groups.gleam", 63).
?DOC(" Broadcast a message to all members of a group.\n").
-spec broadcast(binary(), any()) -> {ok, nil} | {error, group_error()}.
broadcast(Group, Msg) ->
Res = groups_ffi:broadcast(Group, Msg),
case groups_ffi:is_ok_atom(Res) of
true ->
{ok, nil};
false ->
{error, {group_failed, groups_ffi:get_error_reason(Res)}}
end.