syndicate-rkt/syndicate-examples/speed-tests/box-and-client/with-dataspace.rkt

33 lines
1011 B
Racket

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