2017-08-10 19:17:28 +00:00
|
|
|
#lang syndicate
|
2015-12-11 04:55:46 +00:00
|
|
|
;; Simple mutable box and count-to-infinity box client.
|
|
|
|
|
2017-09-13 18:08:01 +00:00
|
|
|
(message-struct set-box (new-value))
|
|
|
|
(assertion-struct box-state (value))
|
2015-12-11 04:55:46 +00:00
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn (field [current-value 0])
|
2016-08-24 16:35:38 +00:00
|
|
|
(assert (box-state (current-value)))
|
2017-07-05 11:13:36 +00:00
|
|
|
(stop-when-true (= (current-value) 10)
|
|
|
|
(log-info "box: terminating"))
|
2016-08-24 16:35:38 +00:00
|
|
|
(on (message (set-box $new-value))
|
|
|
|
(log-info "box: taking on new-value ~v" new-value)
|
|
|
|
(current-value new-value)))
|
2015-12-11 04:55:46 +00:00
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn (stop-when (retracted (observe (set-box _)))
|
2016-08-24 16:35:38 +00:00
|
|
|
(log-info "client: box has gone"))
|
|
|
|
(on (asserted (box-state $v))
|
|
|
|
(log-info "client: learned that box's value is now ~v" v)
|
|
|
|
(send! (set-box (+ v 1)))))
|