syndicate-2017/racket/syndicate/examples/example-quit-world.rkt

38 lines
1.3 KiB
Racket
Raw Normal View History

#lang syndicate/core
;; Demonstrates quit-dataspace.
2015-10-23 23:49:30 +00:00
(require (only-in racket/port read-bytes-line-evt))
(define (spawn-command-listener)
(actor (lambda (e s)
2015-10-23 23:49:30 +00:00
(match e
[(message (inbound (inbound (external-event _ (list #"quit")))))
2015-10-23 23:49:30 +00:00
(printf "Quitting just the leaf actor.\n")
(quit)]
[(message (inbound (inbound (external-event _ (list #"quit-dataspace")))))
(printf "Terminating the whole dataspace.\n")
(transition s (quit-dataspace))]
2015-10-23 23:49:30 +00:00
[_ #f]))
(void)
(sub (inbound (inbound
(external-event (read-bytes-line-evt (current-input-port) 'any) ?))))))
2015-10-23 23:49:30 +00:00
(define (spawn-ticker)
(define (sub-to-alarm)
(sub (inbound (inbound
(external-event (alarm-evt (+ (current-inexact-milliseconds) 1000)) ?)))))
(actor (lambda (e s)
2015-10-23 23:49:30 +00:00
(match e
[(message (inbound (inbound (external-event _ _))))
2015-10-23 23:49:30 +00:00
(printf "Tick!\n")
(transition s
(list (retract ?)
(sub-to-alarm)))]
[_ #f]))
(void)
(sub-to-alarm)))
(printf "Type 'quit' or 'quit-dataspace'.\n")
2017-02-25 16:16:25 +00:00
(dataspace-actor (spawn-command-listener)
(spawn-ticker))