Fetching contributors…
Cannot retrieve contributors at this time
40 lines (34 sloc) 1.06 KB
(ns co.paralleluniverse.pulsar.examples.pingpong-register
"The classic ping-pong example from the Erlang tutorial"
(:use [co.paralleluniverse.pulsar core actors])
(:refer-clojure :exclude [promise await]))
;; This example is intended to be a line-by-line translation of the canonical
;; Erlang [ping-pong example](,
;; so it is not written in idiomatic Clojure.
(defsfn ping [n]
(if (== n 0)
(! :pong :finished)
(println "ping finished"))
(! :pong [:ping @self])
:pong (println "Ping received pong"))
(recur (dec n)))))
(defsfn pong []
:finished (println "Pong finished")
[:ping ping] (do
(println "Pong received ping")
(! ping :pong)
(defn -main []
(register! :pong (spawn pong))
(spawn ping 3)
#_(defn -main []
(let [a1 (register! :pong (spawn pong))
b1 (spawn ping 3)]
(join a1)
(join b1)
(System/exit 0)))