Skip to content

beryl/group

Channel Groups - Named collections of topics for multi-topic broadcasting

Groups let you organize topics and broadcast to all of them at once. Useful for scenarios like broadcasting to all channels in a "team" or sending a system-wide notification.

When running beryl under beryl/supervisor, enable groups with supervisor.with_groups and obtain the handle from supervisor.groups instead of calling start directly.

let assert Ok(groups) = group.start()
let assert Ok(Nil) = group.create(groups, "team:engineering")
let assert Ok(Nil) = group.add(groups, "team:engineering", "room:frontend")
let assert Ok(Nil) = group.add(groups, "team:engineering", "room:backend")
group.broadcast(groups, channels, "team:engineering", "announce", payload)

Errors from group operations

pub type GroupError {
GroupAlreadyExists
GroupNotFound
}

The group already exists

The group was not found

A running Groups instance.

This handle is intentionally opaque so callers cannot forge the backing actor subject or depend on its runtime representation.

pub type Groups

Errors when starting the groups actor.

pub type GroupStartError {
GroupActorStartFailed(error.StartFailure)
}

The actor failed to start

Messages the groups actor handles

pub type Message

Add a topic to a group

Panics if the groups actor is unavailable or does not reply within 5 seconds.

pub fn add(
Groups,
String,
String
) -> Result(Nil, GroupError)

Broadcast a message to all topics in a group

Sends the message to every topic in the named group via beryl.broadcast(). If the group doesn't exist, this is a silent no-op (fire and forget).

pub fn broadcast(
Groups,
beryl.Channels,
String,
String,
json.Json
) -> Nil

Create a new named group

Panics if the groups actor is unavailable or does not reply within 5 seconds.

pub fn create(
Groups,
String
) -> Result(Nil, GroupError)

Delete a group

Panics if the groups actor is unavailable or does not reply within 5 seconds.

pub fn delete(
Groups,
String
) -> Result(Nil, GroupError)

List all group names

Panics if the groups actor is unavailable or does not reply within 5 seconds.

pub fn list_groups(Groups) -> List(String)

Remove a topic from a group

Panics if the groups actor is unavailable or does not reply within 5 seconds.

pub fn remove(
Groups,
String,
String
) -> Result(Nil, GroupError)

Start the groups actor

pub fn start() -> Result(Groups, GroupStartError)

Get all topics in a group

Panics if the groups actor is unavailable or does not reply within 5 seconds.

pub fn topics(
Groups,
String
) -> Result(set.Set(String), GroupError)