2017-08-10 19:04:45 +00:00
|
|
|
#lang syndicate/core
|
2015-03-05 19:56:11 +00:00
|
|
|
|
|
|
|
(require (only-in racket/port read-line-evt))
|
2016-07-12 19:05:56 +00:00
|
|
|
(require/activate "../drivers/timer.rkt")
|
2015-03-05 19:56:11 +00:00
|
|
|
|
2016-07-30 17:02:07 +00:00
|
|
|
(define sub-all-except-meta
|
|
|
|
(patch-seq (sub ?)
|
|
|
|
(unsub (inbound ?))
|
|
|
|
(unsub (outbound ?))))
|
|
|
|
|
2015-03-05 19:56:11 +00:00
|
|
|
(define (quasi-spy e s)
|
|
|
|
(printf "----------------------------------------\n")
|
|
|
|
(printf "QUASI-SPY:\n")
|
|
|
|
(match e
|
|
|
|
[(? patch? p) (pretty-print-patch p)]
|
|
|
|
[other
|
|
|
|
(write other)
|
|
|
|
(newline)])
|
|
|
|
(printf "========================================\n")
|
|
|
|
#f)
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor quasi-spy (void) sub-all-except-meta)
|
2015-03-05 19:56:11 +00:00
|
|
|
|
|
|
|
(define (r e s)
|
|
|
|
(match e
|
2016-07-30 17:02:07 +00:00
|
|
|
[(message body) (transition s (message (outbound `(print (got ,body)))))]
|
2015-03-05 19:56:11 +00:00
|
|
|
[_ #f]))
|
|
|
|
|
|
|
|
(define (b e n)
|
|
|
|
(match e
|
|
|
|
[#f (if (< n 10)
|
|
|
|
(transition (+ n 1) (message `(hello ,n)))
|
|
|
|
#f)]
|
|
|
|
[_ #f]))
|
|
|
|
|
2017-02-25 16:16:25 +00:00
|
|
|
(dataspace-actor (actor r (void) sub-all-except-meta)
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor b 0 '()))
|
2015-03-05 19:56:11 +00:00
|
|
|
|
|
|
|
(define (echoer e s)
|
|
|
|
(match e
|
2016-07-30 17:02:07 +00:00
|
|
|
[(message (inbound (external-event _ (list (? eof-object?)))))
|
2015-03-06 11:21:50 +00:00
|
|
|
(quit)]
|
2016-07-30 17:02:07 +00:00
|
|
|
[(message (inbound (external-event _ (list line))))
|
2015-03-05 19:56:11 +00:00
|
|
|
(transition s (message `(print (got-line ,line))))]
|
|
|
|
[_ #f]))
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor echoer
|
2015-12-03 20:53:07 +00:00
|
|
|
(void)
|
2016-07-30 17:02:07 +00:00
|
|
|
(sub (inbound (external-event (read-line-evt (current-input-port) 'any) ?))))
|
2015-03-05 19:56:11 +00:00
|
|
|
|
|
|
|
(define (ticker e s)
|
|
|
|
(match e
|
|
|
|
[(? patch? p)
|
|
|
|
(printf "TICKER PATCH RECEIVED:\n")
|
|
|
|
(pretty-print-patch p)
|
|
|
|
#f]
|
|
|
|
[(message (timer-expired 'tick now))
|
|
|
|
(printf "TICK ~v\n" now)
|
2015-03-06 11:21:50 +00:00
|
|
|
(if (< s 3)
|
|
|
|
(transition (+ s 1) (message (set-timer 'tick 1000 'relative)))
|
|
|
|
(quit))]
|
2015-03-05 19:56:11 +00:00
|
|
|
[_ #f]))
|
|
|
|
|
2021-05-10 19:30:46 +00:00
|
|
|
(actor (lambda (e s) (quit))
|
|
|
|
#f
|
|
|
|
(message (set-timer 'tick 1000 'relative)))
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor ticker
|
2015-12-03 20:53:07 +00:00
|
|
|
1
|
|
|
|
(patch-seq (sub (observe (set-timer ? ? ?)))
|
|
|
|
(sub (timer-expired 'tick ?))))
|
2015-03-05 19:56:11 +00:00
|
|
|
|
|
|
|
(define (printer e s)
|
|
|
|
(match e
|
|
|
|
[(message (list 'print v))
|
|
|
|
(log-info "PRINTER: ~a" v)
|
|
|
|
#f]
|
|
|
|
[_ #f]))
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor printer
|
2015-12-03 20:53:07 +00:00
|
|
|
(void)
|
|
|
|
(sub `(print ,?)))
|