2016-07-10 16:33:16 +00:00
|
|
|
#lang syndicate/actor
|
2016-06-27 18:42:42 +00:00
|
|
|
;; Demonstrate sending a message to multiple receivers.
|
|
|
|
|
|
|
|
(struct envelope (destination message) #:prefab)
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn (on (message (envelope 'alice $message))
|
2016-08-24 16:35:38 +00:00
|
|
|
(log-info "Alice received ~v" message)))
|
2016-06-27 18:42:42 +00:00
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn (on (message (envelope 'bob $message))
|
2016-08-24 16:35:38 +00:00
|
|
|
(log-info "Bob received ~v" message)))
|
2016-06-27 18:42:42 +00:00
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn*
|
2016-06-27 18:42:42 +00:00
|
|
|
(log-info "Waiting for Alice and Bob.")
|
|
|
|
(until (asserted (observe (envelope 'alice _))))
|
|
|
|
(until (asserted (observe (envelope 'bob _))))
|
|
|
|
|
|
|
|
(log-info "Sending a few messages...")
|
|
|
|
(send! (envelope 'alice "For Alice's eyes only"))
|
|
|
|
(send! (envelope 'bob "Dear Bob, how are you? Kind regards, etc."))
|
|
|
|
(send! (envelope ? "Important announcement!"))
|
|
|
|
|
|
|
|
(log-info "Sent all the messages."))
|