Created
September 10, 2025 03:02
-
-
Save bchase/aabf2a8c2391c83a61d5542e69ccd641 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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