From e124983e05a00573878204d851e7fd75a9cd7672 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 15 Sep 2017 21:45:54 +0100 Subject: [PATCH] Print differently in flip-flop --- racket/syndicate/examples/actor/flip-flop.rkt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/racket/syndicate/examples/actor/flip-flop.rkt b/racket/syndicate/examples/actor/flip-flop.rkt index 140892f..ce59fdb 100644 --- a/racket/syndicate/examples/actor/flip-flop.rkt +++ b/racket/syndicate/examples/actor/flip-flop.rkt @@ -4,8 +4,14 @@ (assertion-struct active ()) (message-struct toggle ()) +(message-struct stdout-message (body)) -(spawn* (define (active-state) +(spawn #:name 'printer + (on (message (stdout-message $body)) + (displayln body))) + +(spawn* #:name 'flip-flop + (define (active-state) (react (assert (active)) (stop-when (message (toggle)) (inactive-state)))) @@ -14,8 +20,8 @@ (active-state)))) (inactive-state)) -(spawn (on (asserted (active)) (printf "Flip-flop is active\n")) - (on (retracted (active)) (printf "Flip-flop is inactive\n")) +(spawn (on (asserted (active)) (send! (stdout-message "Flip-flop is active"))) + (on (retracted (active)) (send! (stdout-message "Flip-flop is inactive"))) (field [next-toggle-time (current-inexact-milliseconds)]) (on (asserted (later-than (next-toggle-time)))