Skip to content

Instantly share code, notes, and snippets.

@bchase
Created September 10, 2025 03:02
Show Gist options
  • Select an option

  • Save bchase/aabf2a8c2391c83a61d5542e69ccd641 to your computer and use it in GitHub Desktop.

Select an option

Save bchase/aabf2a8c2391c83a61d5542e69ccd641 to your computer and use it in GitHub Desktop.
import gleam/otp/actor
import gleam/erlang/process
type Message {
Ping(respond_with: process.Subject(String))
}
pub fn ping() {
let assert Ok(actor) =
actor.new_with_initialiser(100, fn(_) {
let subj = process.new_subject()
let selector = process.new_selector() |> process.select(subj)
actor.initialised(Nil)
|> actor.returning(subj)
|> actor.selecting(selector)
|> Ok
})
|> actor.on_message(fn(state, msg: Message) {
case msg {
Ping(respond_with) -> {
echo "Pong"
process.send(respond_with, "pong")
actor.continue(state)
}
}
})
|> actor.start
echo process.call(actor.data, 500, Ping)
}
pub fn main() -> Nil {
ping()
Nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment