marketplace-2014/support/spy.rkt

31 lines
826 B
Racket
Raw Normal View History

2014-08-06 19:16:50 +00:00
#lang racket/base
2013-03-29 03:00:29 +00:00
2014-08-06 19:16:50 +00:00
(require "../sugar.rkt")
2013-03-29 03:00:29 +00:00
(provide generic-spy)
2014-08-06 19:16:50 +00:00
;; generic-spy : (All (ParentState) Any -> (Spawn ParentState))
2013-03-29 03:00:29 +00:00
(define (generic-spy label)
(name-process `(generic-spy ,label)
2014-08-06 19:16:50 +00:00
(spawn (transition (void)
(observe-publishers (wild)
(match-orientation orientation
(match-conversation topic
(match-interest-type interest
(match-reason reason
(on-presence (begin (write `(,label ENTER (,orientation ,topic ,interest)))
2013-03-29 03:00:29 +00:00
(newline)
(flush-output)
'()))
2014-08-06 19:16:50 +00:00
(on-absence (begin (write `(,label EXIT (,orientation ,topic ,interest)))
(newline)
(display reason)
(newline)
(flush-output)
'()))
(on-message
[p (begin (write `(,label MSG ,p))
(newline)
(flush-output)
'())]))))))))))