processgroups

Types

For monitoring, we use the gleam/erlang/process module and their way of handling messages. The GroupMonitor type is constructed when monitoring a process group. You can than use selecting_process_group_monitor To receive GroupMonitorEvent messages using gleam/erlang/process.select.

pub opaque type GroupMonitor(group)

The events send when monitoring a process group.

pub type GroupMonitorEvent(group) {
  ProcessJoined(group: group, pids: List(process.Pid))
  ProcessLeft(group: group, pids: List(process.Pid))
}

Constructors

  • ProcessJoined(group: group, pids: List(process.Pid))

    Some processes have joined

  • ProcessLeft(group: group, pids: List(process.Pid))

    Same process have left

A scope for process groups is an atom, we type alias to make it clearer

pub type Scope =
  atom.Atom

Functions

pub fn demonitor(group: a) -> Bool
pub fn demonitor_scope(scope: Atom, group: a) -> Bool
pub fn erlang_monitor_scope(
  scope: Atom,
  group: a,
) -> #(Reference, List(Pid))
pub fn get_local_members(group: a) -> List(Pid)
pub fn get_local_members_scope(
  scope: Atom,
  group: a,
) -> List(Pid)
pub fn get_members(group: a) -> List(Pid)
pub fn get_members_scope(scope: Atom, group: a) -> List(Pid)
pub fn join(group: a, pid: Pid) -> Nil
pub fn join_many(group: a, pids: List(Pid)) -> Nil
pub fn join_scope(scope: Atom, group: a, pid: Pid) -> Nil
pub fn join_scope_many(
  scope: Atom,
  group: a,
  pids: List(Pid),
) -> Nil
pub fn leave(group: a, pid: Pid) -> Nil
pub fn leave_many(group: a, pids: List(Pid)) -> Nil
pub fn leave_many_scope(
  scope: Atom,
  group: a,
  pids: List(Pid),
) -> Atom
pub fn leave_scope(scope: Atom, group: a, pid: Pid) -> Atom
pub fn monitor(group: a) -> #(GroupMonitor(a), List(Pid))
pub fn monitor_scope(
  scope: Atom,
  group: a,
) -> #(GroupMonitor(a), List(Pid))
pub fn selecting_process_group_monitor(
  selector: Selector(a),
  monitor: GroupMonitor(b),
  mapping: fn(GroupMonitorEvent(b)) -> a,
) -> Selector(a)

Receive monitoring events.

Example

import pg_for_gleam as pg
import gelam/erlang/process

let monitor = pg.monitor(SomeProcessGroup)

let selector = pg.selecting_process_group_monitor(
  selector: new_selector(),
  monitor: monitor,
  mapping: fn(gme) {gme}
)

case select(selector) {
  Ok(ProcessJoined(_, pids)) -> io.print("some process joined")
  Ok(ProcessLeft(_, pids)) -> io.print("some process left")
  _ -> panic
}
pub fn start(scope: Atom) -> Result(Pid, Dynamic)
pub fn start_link() -> Result(Pid, Dynamic)
pub fn start_link_with_scope(scope: Atom) -> Result(Pid, Dynamic)
pub fn which_groups() -> List(a)
pub fn which_groups_scope(scope: Atom) -> List(a)
Search Document