Racket implementation of Dataspaces and Syndicate.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2010-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
#lang syndicate
;; Simple mutable box and count-to-infinity box client.
(message-struct set-box (new-value))
(assertion-struct box-state (value))
(module+ main
(actor-system/dataspace (ds)
(spawn #:name 'box
(define-field current-value 0)
(at ds
(assert (box-state (current-value)))
(when (message (set-box $new-value))
(log-info "box: taking on new-value ~v" new-value)
(current-value new-value)))
(stop-when-true (= (current-value) 10)
(log-info "box: terminating")))
(spawn #:name 'client
(at ds
(stop-when (retracted (Observe (:pattern (set-box ,_)) _))
(log-info "client: box has gone"))
(when (asserted (box-state $v))
(log-info "client: learned that box's value is now ~v" v)
(send! ds (set-box (+ v 1))))
(when (retracted (box-state _))
(log-info "client: box state disappeared"))))))