distribute/groups
Types
pub type GroupError {
GroupFailed(String)
EncodeFailed(codec.EncodeError)
MemberConversionFailed(String)
}
Constructors
-
GroupFailed(String)A group operation failed (e.g. invalid group name or internal error).
-
EncodeFailed(codec.EncodeError)Message encoding failed during broadcast.
-
MemberConversionFailed(String)Member conversion failed (e.g. invalid Pid to Subject).
Re-export Pid from gleam/erlang/process for API compatibility.
Use gleam/erlang/process.Pid directly in new code.
pub type Pid =
process.Pid
Values
pub fn broadcast(
group: String,
msg: a,
) -> Result(Nil, GroupError)
Deprecated: Use broadcast_typed with a codec for type-safe group messaging.
Broadcast a message to all members of a group.
This function bypasses all type checking and encoding validation.
pub fn broadcast_typed(
group: String,
msg: a,
encoder: fn(a) -> Result(BitArray, codec.EncodeError),
) -> Result(Nil, GroupError)
Broadcast a typed message to all members of a group. The message is encoded using the provided encoder before sending. Members should be expecting BitArray messages.
pub fn join(
group: String,
pid: process.Pid,
) -> Result(Nil, GroupError)
Join a process to a named group.
pub fn join_typed(
group: String,
subject: process.Subject(msg),
) -> Result(Nil, GroupError)
Join a typed subject to a named group.
pub fn leave(
group: String,
pid: process.Pid,
) -> Result(Nil, GroupError)
Remove a process from a named group.
pub fn leave_typed(
group: String,
subject: process.Subject(msg),
) -> Result(Nil, GroupError)
Remove a typed subject from a named group.
pub fn members(group: String) -> List(process.Pid)
Get the list of member pids in a group.
pub fn members_typed(group: String) -> List(process.Pid)
Get the list of typed members in a group. Returns raw Pids as we cannot safely convert them to Subjects without knowing their message types. Use this with caution or create Subjects using process.unsafely_create_subject if you know the message type.