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: process.Subject(m),
    monitor: process.Monitor,
  )
}

Constructors

pub type Topic(m) {
  Topic(process.Subject(Message(m)))
}

Constructors

Values

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

Broadcasts a message to all subscribers of the given topic.

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

Destroys the given topic, unsubscribing all clients.

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

Returns a set of all subscribers to the given topic.

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

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

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

Subscribes the given client to the given topic.

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

Unsubscribes the given client from the given topic.

Search Document