glubsub

Package Version Hex Docs

tiny pubsub inspired abstraction.

gleam add glubsub
import gleam/otp/actor
import gleam/io
import glubsub

type Message {
  Broadcast(String)
}

pub fn main() {
  let assert Ok(topic) = glubsub.new_topic()

  let assert Ok(actor) = actor.start(Nil, handle_message)

  glubsub.subscribe(topic, actor)

  glubsub.broadcast(topic, Broadcast("Hello Wobble!"))
}

fn handle_message(message: Message, state) -> actor.Next(a, Nil) {
  case message {
    Broadcast(msg) -> {
      io.println(msg)
      actor.continue(state)
    }
  }
}

Development

gleam test  # Run the tests
Search Document