Skip to content

beryl/supervisor

OTP supervision tree for beryl subsystems.

This module does not start processes directly. It builds a supervisor child specification for the application's supervision tree, while stable named subjects let callers construct the subsystem handles before that tree starts.

import beryl
import beryl/presence
import beryl/supervisor
import beryl/wire
import gleam/otp/static_supervisor
let beryl =
supervisor.config(beryl.config(wire.phoenix_codec()))
|> supervisor.with_presence(presence.default_config("node1"))
|> supervisor.with_groups()
let assert Ok(_root) =
static_supervisor.new(static_supervisor.OneForOne)
|> static_supervisor.add(supervisor.start(beryl))
|> static_supervisor.start()
let channels = supervisor.channels(beryl)

Configuration and stable handles for beryl's supervised subsystems.

Construct it with config, add optional subsystems with the with_* functions, add start to the application's supervisor, then use channels, presence, and groups to access the named processes.

pub type SupervisedConfig

The channels handle for this supervised beryl instance.

Add start to a running application supervisor before using the handle.

pub fn channels(SupervisedConfig) -> beryl.Channels

Configure the beryl supervision subtree.

The coordinator is always included. Presence and groups are opt-in via with_presence and with_groups.

pub fn config(beryl.Config) -> SupervisedConfig

The groups handle, if groups were configured.

pub fn groups(SupervisedConfig) -> option.Option(group.Groups)

The presence handle, if presence was configured.

pub fn presence(SupervisedConfig) -> option.Option(presence.Presence)

Build beryl's supervisor child specification.

Add the returned specification to the application's supervision tree. The subtree isolates the connection limiter from a nested rest-for-one channel supervisor. A coordinator crash therefore restarts its dependent presence and groups processes while preserving registrations and live connection counts.

pub fn start(SupervisedConfig) -> supervision.ChildSpecification(static_supervisor.Supervisor)

Enable named channel groups.

pub fn with_groups(SupervisedConfig) -> SupervisedConfig

Enable presence tracking with the given configuration.

pub fn with_presence(
SupervisedConfig,
presence.Config
) -> SupervisedConfig