#lang imperative-syndicate/test-implementation
;; See .../syndicate/examples/actor/example-responsibility-transfer-1.rkt

(test-case
    [(spawn #:name 'demand-watcher
            (during/spawn 'demand
              #:name (gensym 'intermediate-demand-asserter)
              (assert 'intermediate-demand)))

     (spawn #:name 'intermediate-demand-watcher
            (during/spawn 'intermediate-demand
              #:name (gensym 'supply-asserter)
              (assert 'supply)))

     (spawn* #:name 'driver
             (react (on (asserted 'supply) (displayln "Supply asserted."))
                    (on (retracted 'supply) (displayln "Supply retracted.")))
             (until (asserted (observe 'demand)))
             (displayln "Asserting demand.")
             (assert! 'demand)
             (until (asserted 'supply))
             (displayln "Glitching demand.")
             (retract! 'demand)
             (flush!)
             (assert! 'demand)
             (displayln "Demand now steady."))]
  no-crashes
  (expected-output (list "Asserting demand."
                         "Supply asserted."
                         "Glitching demand."
                         "Demand now steady."
                         "Supply retracted."
                         "Supply asserted.")))
