box-and-client actor example

This commit is contained in:
Tony Garnock-Jones 2015-12-11 17:55:46 +13:00
parent 424f38b268
commit 91c2d6a3c7
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#lang prospect
;; Simple mutable box and count-to-infinity box client.
(require prospect/actor)
(struct set-box (new-value) #:transparent)
(struct box-state (value) #:transparent)
(%%boot
(lambda ()
(actor
(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)))
(actor (forever (on (asserted (box-state $v))
(log-info "client: learned that box's value is now ~v" v)
(send! (set-box (+ v 1))))))
)))