syndicate-2017/racket/syndicate/examples/example-meta-echo.rkt

37 lines
1.5 KiB
Racket
Raw Normal View History

#lang syndicate/core
2016-02-12 03:26:53 +00:00
;; Test case for a historical bug in Syndicate.
2016-02-07 21:14:12 +00:00
;;
;; When the bug existed, this program received four SCN events in
2016-02-07 21:14:12 +00:00
;; total, whereas it should receive only two.
;;
2016-02-12 03:26:53 +00:00
;; While metamessages were "echo cancelled", and receivers only ever
;; got one copy of a sent metamessage no matter how many metas there
;; were, state changes were not. Issuing a quick enough "pulse" of
;; metaassertion while maintaining interest in it led to an "echo":
2016-02-07 21:14:12 +00:00
;; multiple receipts of the pulse.
;;
2016-02-12 03:26:53 +00:00
;; The fix was to adjust the implementation of state change
2016-02-07 21:14:12 +00:00
;; notifications to cancel the echo for metaassertions.
;;
;; 20160730 I'm in the process of revising the design of dataspace
;; relaying to avoid this problem in a different way. Instead of just
;; having `at-meta` for both inbound and outbound assertions, there
;; are now two constructors, `inbound` and `outbound`, and the relay
;; function of the dataspace pays attention to each in a different
;; way. Now there cannot be (accidental) routing loops: asserting
;; something `outbound`, no matter how briefly, will only ever result
;; in a pulse of an `inbound` assertion.
2016-02-07 21:14:12 +00:00
2016-04-01 23:53:46 +00:00
(require syndicate/pretty)
2016-02-07 21:14:12 +00:00
2017-02-25 16:16:25 +00:00
(dataspace-actor
(actor (lambda (e counter)
2016-02-07 21:14:12 +00:00
(and e
(let ((new-counter (+ counter 1)))
2016-04-01 23:53:46 +00:00
(printf "Received event ~a:\n~a\n" new-counter (syndicate-pretty-print->string e))
2016-02-07 21:14:12 +00:00
(transition (+ counter 1) '()))))
0
(list (patch-seq (assert (outbound 'x))
(sub (inbound 'x)))
(retract (outbound 'x)))))