From a82b428f44ad5fe15d4eced71da0e629e2e65cf7 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 15 Sep 2017 20:34:16 +0100 Subject: [PATCH] racket/syndicate/examples/actor/flip-flop.rkt --- racket/syndicate/examples/actor/flip-flop.rkt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 racket/syndicate/examples/actor/flip-flop.rkt diff --git a/racket/syndicate/examples/actor/flip-flop.rkt b/racket/syndicate/examples/actor/flip-flop.rkt new file mode 100644 index 0000000..140892f --- /dev/null +++ b/racket/syndicate/examples/actor/flip-flop.rkt @@ -0,0 +1,23 @@ +#lang syndicate + +(require/activate syndicate/drivers/timestate) + +(assertion-struct active ()) +(message-struct toggle ()) + +(spawn* (define (active-state) + (react (assert (active)) + (stop-when (message (toggle)) + (inactive-state)))) + (define (inactive-state) + (react (stop-when (message (toggle)) + (active-state)))) + (inactive-state)) + +(spawn (on (asserted (active)) (printf "Flip-flop is active\n")) + (on (retracted (active)) (printf "Flip-flop is inactive\n")) + + (field [next-toggle-time (current-inexact-milliseconds)]) + (on (asserted (later-than (next-toggle-time))) + (send! (toggle)) + (next-toggle-time (+ (next-toggle-time) 1000))))