Print differently in flip-flop

This commit is contained in:
Tony Garnock-Jones 2017-09-15 21:45:54 +01:00
parent a82b428f44
commit e124983e05
1 changed files with 9 additions and 3 deletions

View File

@ -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)))