Make box-and-client work better with raco test

This commit is contained in:
Tony Garnock-Jones 2021-06-03 22:50:37 +02:00
parent d648af920a
commit 6a0bcb1246
1 changed files with 20 additions and 19 deletions

View File

@ -4,23 +4,24 @@
(struct set-box (new-value) #:prefab) (struct set-box (new-value) #:prefab)
(struct box-state (value) #:prefab) (struct box-state (value) #:prefab)
(actor-system/dataspace (ds) (module+ main
(spawn #:name 'box (actor-system/dataspace (ds)
(define-field current-value 0) (spawn #:name 'box
(at ds (define-field current-value 0)
(assert (box-state (current-value))) (at ds
(when (message (set-box $new-value)) (assert (box-state (current-value)))
(log-info "box: taking on new-value ~v" new-value) (when (message (set-box $new-value))
(current-value new-value))) (log-info "box: taking on new-value ~v" new-value)
(stop-when-true (= (current-value) 10) (current-value new-value)))
(log-info "box: terminating"))) (stop-when-true (= (current-value) 10)
(log-info "box: terminating")))
(spawn #:name 'client (spawn #:name 'client
(at ds (at ds
(stop-when (retracted (Observe (:pattern (set-box ,_)) _)) (stop-when (retracted (Observe (:pattern (set-box ,_)) _))
(log-info "client: box has gone")) (log-info "client: box has gone"))
(when (asserted (box-state $v)) (when (asserted (box-state $v))
(log-info "client: learned that box's value is now ~v" v) (log-info "client: learned that box's value is now ~v" v)
(send! ds (set-box (+ v 1)))) (send! ds (set-box (+ v 1))))
(when (retracted (box-state _)) (when (retracted (box-state _))
(log-info "client: box state disappeared"))))) (log-info "client: box state disappeared"))))))