<- <-* <-wait <-wait* <-reply <-reply* <-reply-wait <-reply-wait*
- call-with-message msg-receive msg-val
+ call-with-message mbody-receive mbody-val
run-hive
bootstrap-message
argument. Similar to call-with-values in concept."
(apply proc message (message-body message)))
-;; (msg-receive (<- bar baz)
+;; (mbody-receive (<- bar baz)
;; (baz)
;; basil)
-;; Emacs: (put 'msg-receive 'scheme-indent-function 2)
+;; Emacs: (put 'mbody-receive 'scheme-indent-function 2)
;; @@: Or receive-msg or receieve-message or??
-(define-syntax-rule (msg-receive arglist message body ...)
+(define-syntax-rule (mbody-receive arglist message body ...)
"Call body with arglist (which can accept arguments like lambda*)
applied from the message-body of message."
(call-with-message message
(lambda* arglist
body ...)))
-(define (msg-val message)
+(define (mbody-val message)
"Retrieve the first value from the message-body of message.
Like single value return from a procedure call. Probably the most
common case when waiting on a reply from some action invocation."
(address-actor-id room)))
;; Find all droids in this room and exterminate the infected ones.
- (msg-receive (_ #:key list-droids droid-ids #:allow-other-keys)
+ (mbody-receive (_ #:key list-droids droid-ids #:allow-other-keys)
(<-wait room 'list-droids)
(for-each
(lambda (droid-id)
(cond
;; Looks like it's infected
- ((msg-val (<-wait droid-id 'infection-expose))
+ ((mbody-val (<-wait droid-id 'infection-expose))
;; Inform that it's infected
(<- overseer 'transmission
#:text (format #f "~a found to be infected... taking out"
;; Keep firing till it's dead.
(let ((still-alive #t))
(while still-alive
- (msg-receive (response #:key alive #:allow-other-keys)
+ (mbody-receive (response #:key alive #:allow-other-keys)
(<-wait droid-id 'get-shot)
(<- overseer 'transmission
#:text (droid-status-format response))
droid-ids))
;; Switch to next room, if there is one.
- (set! room (msg-val (<-wait room 'get-next-room))))
+ (set! room (mbody-val (<-wait room 'get-next-room))))
;; Good job everyone! Shut down the operation.
(<- overseer 'transmission
"Pester direct report until they're done with their task."
(display "manager> Are you done yet???\n")
(let ((still-working
- (msg-val (<-wait (manager-direct-report manager)
- 'done-yet?))))
+ (mbody-val (<-wait (manager-direct-report manager)
+ 'done-yet?))))
(if still-working
(begin (display "manager> Harumph!\n")
(8sleep 1)
"<-wait", as it sounds, waits for a reply, and returns a reply
message.
In this case there's a value in the body of the message we want,
-so we pull it out with msg-val.
+so we pull it out with mbody-val.
(It's possible for a remote actor to return multiple values, in which
-case we'd want to use msg-receive, but that's a bit more complicated.)
+case we'd want to use mbody-receive, but that's a bit more
+complicated.)
Of course, we need to update our worker accordingly as well.
** COMMENT Websockets
* Addendum
+** Recommended .emacs additions
+
+In order for =mbody-receive= to indent properly, put this in your
+.emacs:
+
+#+BEGIN_SRC emacs-lisp
+(put 'mbody-receive 'scheme-indent-function 2)
+#+END_SRC
+
** 8sync and Fibers
One other major library for asynchronous communication in Guile-land
(define* (antsy-caller-pester-rep actor message #:key who-to-call)
(~display "customer> I'm calling customer service about this!\n")
- (msg-receive (first-reply #:key msg)
+ (mbody-receive (first-reply #:key msg)
(<-wait who-to-call 'field-call)
(if (message-auto-reply? first-reply)
(~display "customer> Whaaaaat? I can't believe I got voice mail!\n")
(begin
(~format "*customer hears*: ~a\n" msg)
- (msg-receive (second-reply #:key *auto-reply*)
+ (mbody-receive (second-reply #:key *auto-reply*)
(<-reply-wait first-reply
#:msg "Yes, it didn't work, I'm VERY ANGRY!")
(if (message-auto-reply? second-reply)
(define (rep-field-call actor message)
(~display "good-rep> Hm, another call from a customer...\n")
- (msg-receive (reply #:key msg)
+ (mbody-receive (reply #:key msg)
(<-reply-wait message #:msg "Have you tried turning it off and on?")
(~format "*rep hears*: ~a\n" msg)
(~display "good-rep> I'm sorry, that's all I can do for you.\n")))