syndicate-2017/racket/syndicate/examples/box-and-client.rkt

25 lines
917 B
Racket
Raw Normal View History

2016-04-01 23:53:46 +00:00
#lang syndicate
2015-11-03 02:40:12 +00:00
;; Simple mutable box and count-to-infinity box client.
(struct set-box (new-value) #:transparent)
(struct box-state (value) #:transparent)
(spawn (lambda (e current-value)
(match-event e
2015-11-03 02:40:12 +00:00
[(message (set-box new-value))
(log-info "box: taking on new-value ~v" new-value)
2015-11-03 02:40:12 +00:00
(transition new-value (patch-seq (retract (box-state current-value))
(assert (box-state new-value))))]))
2015-11-03 02:40:12 +00:00
0
(patch-seq (sub (set-box ?))
(assert (box-state 0))))
2015-11-03 02:40:12 +00:00
(spawn (lambda (e s)
(match-event e
2015-11-03 02:40:12 +00:00
[(patch added removed)
2016-02-05 18:20:13 +00:00
(transition s (for-trie/list ([(box-state $v) added])
(log-info "client: learned that box's value is now ~v" v)
(message (set-box (+ v 1)))))]))
2015-11-03 02:40:12 +00:00
(void)
(patch-seq (sub (box-state ?))))