Simple PubSub for gleam

Simple PubSub for gleam, based on process groups.

Package Version Hex Docs

Usage

Add this library to your Gleam project

gleam add simple_pubsub

And use it in your project

Example

import simple_pubsub as ps
import process_groups
import gleam/erlang/process
// Messages we want to send over the PubSub
type PubSubMessage{
PubSubMessage
}
pub fn main() {
// start process groups, needed for pubsub
process_groups.start_link()
// create a pubsub
let pubsub = ps.new_pubsub()
// subscribe, normally you would subscribe another process than this one
let subscription = ps.subscribe(pubsub, process.self())
// broadcast a message
ps.broadcast(pubsub, PubSubMessage)
// receive the message
let assert Ok(PubSubMessage) = ps.receive(subscription, 100)
}

Development

gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell