2015-10-23 23:49:30 +00:00
|
|
|
#lang prospect
|
2016-01-18 19:29:48 +00:00
|
|
|
;; Demonstrates quit-network.
|
2015-10-23 23:49:30 +00:00
|
|
|
|
|
|
|
(require (only-in racket/port read-bytes-line-evt))
|
|
|
|
|
|
|
|
(define (spawn-command-listener)
|
|
|
|
(spawn (lambda (e s)
|
|
|
|
(match e
|
|
|
|
[(message (at-meta (at-meta (external-event _ (list #"quit")))))
|
|
|
|
(printf "Quitting just the leaf actor.\n")
|
|
|
|
(quit)]
|
2016-01-18 19:29:48 +00:00
|
|
|
[(message (at-meta (at-meta (external-event _ (list #"quit-network")))))
|
2015-10-23 23:49:30 +00:00
|
|
|
(printf "Terminating the whole network.\n")
|
2016-01-18 19:29:48 +00:00
|
|
|
(transition s (quit-network))]
|
2015-10-23 23:49:30 +00:00
|
|
|
[_ #f]))
|
|
|
|
(void)
|
|
|
|
(sub (external-event (read-bytes-line-evt (current-input-port) 'any) ?)
|
|
|
|
#:meta-level 2)))
|
|
|
|
|
|
|
|
(define (spawn-ticker)
|
|
|
|
(define (sub-to-alarm)
|
|
|
|
(sub (external-event (alarm-evt (+ (current-inexact-milliseconds) 1000)) ?) #:meta-level 2))
|
|
|
|
(spawn (lambda (e s)
|
|
|
|
(match e
|
|
|
|
[(message (at-meta (at-meta (external-event _ _))))
|
|
|
|
(printf "Tick!\n")
|
|
|
|
(transition s
|
|
|
|
(list (retract ?)
|
|
|
|
(sub-to-alarm)))]
|
|
|
|
[_ #f]))
|
|
|
|
(void)
|
|
|
|
(sub-to-alarm)))
|
|
|
|
|
2016-01-18 19:29:48 +00:00
|
|
|
(printf "Type 'quit' or 'quit-network'.\n")
|
|
|
|
(spawn-network (spawn-command-listener)
|
|
|
|
(spawn-ticker))
|