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.

34 lines
1.1 KiB

#lang syndicate
;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
(require "protocol.rkt")
(require "stats.rkt")
(define box
(action (ds LIMIT REPORT_EVERY)
(spawn #:name 'box
(define-field value 0)
(define reporter (report-stats REPORT_EVERY))
(at ds
(assert (BoxState (value)))
(when (message (SetBox $new-value))
(reporter new-value)
(when (= new-value LIMIT) (stop-current-facet))
(value new-value))))))
(define client
(action (ds)
(spawn #:name 'client
(define root-facet this-facet)
(at ds
(when (asserted (BoxState $value)) (send! ds (SetBox (+ value 1))))
(during (BoxState _)
(on-stop (log-info "Client detected box termination")
(stop-facet root-facet)))))))
(module+ main
(time
(actor-system/dataspace (ds)
(box this-turn ds 500000 100000)
(client this-turn ds))))