Make send-message topic optional, defaulting to a publish of the body itself.

This commit is contained in:
Tony Garnock-Jones 2012-04-17 12:43:21 -04:00
parent 4bf766daff
commit 1b60994028
1 changed files with 5 additions and 3 deletions

View File

@ -27,7 +27,8 @@
(rename-out [make-add-role add-role])
(except-out (struct-out delete-role) delete-role)
(rename-out [make-delete-role delete-role])
(struct-out send-message)
(except-out (struct-out send-message) send-message)
(rename-out [make-send-message send-message])
(except-out (struct-out spawn) spawn)
(rename-out [make-spawn spawn])
(except-out (struct-out kill) kill)
@ -101,7 +102,7 @@
;; Ks are various TrapKs or #f, signifying lack of interest.
(struct add-role (topics handlers k) #:prefab)
(struct delete-role (eid reason) #:prefab)
(struct send-message (topic body) #:prefab)
(struct send-message (body topic) #:prefab)
(struct spawn (main k) #:prefab)
(struct kill (pid reason) #:prefab)
@ -152,6 +153,7 @@
(define (make-transition state . actions) (transition state actions))
(define (make-add-role topics handlers [k #f]) (add-role topics handlers k))
(define (make-delete-role eid [reason #f]) (delete-role eid reason))
(define (make-send-message body [topic (topic-publisher body)]) (send-message body topic))
(define (make-spawn main [k #f]) (spawn main k))
(define (make-kill [pid #f] [reason #f]) (kill pid reason))
@ -250,7 +252,7 @@
(match preaction
[(add-role topics hs k) (do-subscribe pid (ensure-topic-union topics) hs k state)]
[(delete-role eid reason) (do-unsubscribe pid eid reason state)]
[(send-message topic body) (route-and-deliver topic body state)]
[(send-message body topic) (route-and-deliver topic body state)]
[(spawn main k) (do-spawn pid main k state)]
[(kill pid-to-kill reason) (do-kill (or pid-to-kill pid) reason state)]))