2021-06-03 20:54:36 +00:00
|
|
|
#lang syndicate
|
2021-06-04 14:20:14 +00:00
|
|
|
;;; SPDX-License-Identifier: LGPL-3.0-or-later
|
2023-01-16 14:57:29 +00:00
|
|
|
;;; SPDX-FileCopyrightText: Copyright © 2021-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
2021-05-27 09:28:10 +00:00
|
|
|
|
2021-06-03 21:22:46 +00:00
|
|
|
(require "protocol.rkt")
|
|
|
|
(require "stats.rkt")
|
2021-05-28 07:57:11 +00:00
|
|
|
|
2021-06-10 09:42:07 +00:00
|
|
|
(define (box ds LIMIT REPORT_EVERY)
|
|
|
|
(spawn #:name 'box
|
|
|
|
(define-field value 0)
|
|
|
|
(define reporter (report-stats REPORT_EVERY))
|
|
|
|
(at ds
|
|
|
|
(assert (BoxState (value)))
|
2021-06-17 11:38:30 +00:00
|
|
|
(on (message (SetBox $new-value))
|
2021-06-10 09:42:07 +00:00
|
|
|
(reporter new-value)
|
|
|
|
(when (= new-value LIMIT) (stop-current-facet))
|
|
|
|
(value new-value)))))
|
2021-06-01 08:04:10 +00:00
|
|
|
|
2021-06-10 09:42:07 +00:00
|
|
|
(define (client ds)
|
|
|
|
(spawn #:name 'client
|
|
|
|
(define root-facet this-facet)
|
|
|
|
(at ds
|
2021-06-17 11:38:30 +00:00
|
|
|
(on (asserted (BoxState $value)) (send! (SetBox (+ value 1))))
|
2021-06-10 09:42:07 +00:00
|
|
|
(during (BoxState _)
|
|
|
|
(on-stop (log-info "Client detected box termination")
|
|
|
|
(stop-facet root-facet))))))
|
2021-05-28 07:57:11 +00:00
|
|
|
|
2021-05-31 11:07:37 +00:00
|
|
|
(module+ main
|
|
|
|
(time
|
2021-06-17 12:57:06 +00:00
|
|
|
(standard-actor-system (ds)
|
2021-06-10 09:42:07 +00:00
|
|
|
(box ds 500000 100000)
|
|
|
|
(client ds))))
|