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

18 lines
611 B
Racket
Raw Normal View History

2016-04-01 23:53:46 +00:00
#lang syndicate
2015-12-11 04:55:46 +00:00
;; Simple mutable box and count-to-infinity box client.
2016-04-01 23:53:46 +00:00
(require syndicate/actor)
2015-12-11 04:55:46 +00:00
(struct set-box (new-value) #:transparent)
(struct box-state (value) #:transparent)
(actor (forever #:collect [(current-value 0)]
(assert (box-state current-value))
(on (message (set-box $new-value))
(log-info "box: taking on new-value ~v" new-value)
new-value)))
2015-12-11 04:55:46 +00:00
(actor (forever (on (asserted (box-state $v))
(log-info "client: learned that box's value is now ~v" v)
(send! (set-box (+ v 1))))))