glubsub

This module implements a simple pubsub system using gleam actors.

Types

pub opaque type GlubsubError
pub opaque type Message(m)
pub type Subscriber(m) {
  Subscriber(client: Subject(m), monitor: ProcessMonitor)
}

Constructors

  • Subscriber(client: Subject(m), monitor: ProcessMonitor)
pub type Topic(m) {
  Topic(Subject(Message(m)))
}

Constructors

  • Topic(Subject(Message(m)))

Functions

pub fn broadcast(topic: Topic(a), message: a) -> Result(Nil, Nil)

Broadcasts a message to all subscribers of the given topic.

pub fn destroy_topic(topic: Topic(a)) -> Nil

Destroys the given topic, unsubscribing all clients.

pub fn get_subscribers(topic: Topic(a)) -> List(Subscriber(a))

Returns a set of all subscribers to the given topic.

pub fn new_topic() -> Result(Topic(a), GlubsubError)

Creates a new topic. Which is a pubsub channel that clients can subscribe to.

pub fn subscribe(
  topic: Topic(a),
  client: Subject(a),
) -> Result(Nil, GlubsubError)

Subscribes the given client to the given topic.

pub fn unsubscribe(
  topic: Topic(a),
  client: Subject(a),
) -> Result(Nil, GlubsubError)

Unsubscribes the given client from the given topic.

Search Document