simple_pubsub

Types

A pubsub, where process can subscribe and anyone can broadcast

pub type PubSub(message) {
  PubSub(tag: erlang.Reference)
}

Constructors

  • PubSub(tag: erlang.Reference)

A Subscription is crated by subscribing to a PubSub and can be used to receive broadcast messages on the owning thread.

pub type Subscription(message) {
  Subscription(pubsub: PubSub(message), owner: process.Pid)
}

Constructors

  • Subscription(pubsub: PubSub(message), owner: process.Pid)

Functions

pub fn broadcast(pubsub: PubSub(a), msg: a) -> Nil

Send a message to all processes, subscribed to the PubSub

pub fn demonitor(pubsub: PubSub(a)) -> Bool

Stop monitoring a PubSub.

pub fn monitor(
  pubsub: PubSub(a),
) -> #(GroupMonitor(Reference), List(Pid))

Monitor a PubSub. A pg.GorupMonitor event will be send, when a process subscribes or unsubscribes.

pub fn new_pubsub() -> PubSub(a)

Create a new pubsub

pub fn receive(
  from subject: Subscription(a),
  within milliseconds: Int,
) -> Result(a, Nil)

Receive a message on a subscription. has to be done on the process owning the Subscription, which is passed to subscribe

pub fn selecting_pubsub_subject(
  selector: Selector(a),
  subject: Subscription(b),
  handler: fn(b) -> a,
) -> Selector(a)

Create a Selector for receiving PubSub messages.

pub fn subscribe(pubsub: PubSub(a), pid: Pid) -> Subscription(a)

Subscribe a process to a PubSub.

pub fn unsubscribe(
  subscription: Subscription(a),
  pid: Pid,
) -> Nil

Unsubsribe a process from a PubSub.

Search Document