actors: Don't reply to a message when the messsage doesn't need a reply.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 20 Jan 2017 23:58:20 +0000 (17:58 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sat, 21 Jan 2017 00:01:00 +0000 (18:01 -0600)
* 8sync/actors.scm (<-reply, <-reply*, <-reply-wait, <-reply-wait*):
Only reply to messages if they're waiting on a reply still.
This avoids the challenges of actors never having requested a
reply in the first place resulting in trying to resume a waiting
coroutine that doesn't exist, as well as maybe the bonus one of not
replying multiple times to a message.

8sync/actors.scm

index c805067b21def054ff2d3f6233e89824671a96e9..04e1c06a4e2b563a7d6dfb2c63b76959cf7ee12f 100644 (file)
 
 (define (<-reply original-message . message-body-args)
   "Reply to a message"
 
 (define (<-reply original-message . message-body-args)
   "Reply to a message"
-  (send-message '() (%current-actor) (message-from original-message) '*reply*
-                original-message #f message-body-args))
+  (when (message-needs-reply? original-message)
+    (send-message '() (%current-actor) (message-from original-message) '*reply*
+                  original-message #f message-body-args)))
 
 (define (<-reply* send-options original-message . message-body-args)
   "Like <-reply, but allows extra parameters via send-options"
 
 (define (<-reply* send-options original-message . message-body-args)
   "Like <-reply, but allows extra parameters via send-options"
     (send-message send-options actor
                   (message-from original-message) '*reply*
                   original-message #f message-body-args))
     (send-message send-options actor
                   (message-from original-message) '*reply*
                   original-message #f message-body-args))
-  (apply really-send send-options))
+  (when (message-needs-reply? original-message)
+    (apply really-send send-options)))
 
 (define (<-auto-reply actor original-message)
   "Auto-reply to a message.  Internal use only!"
 
 (define (<-auto-reply actor original-message)
   "Auto-reply to a message.  Internal use only!"
 
 (define (<-reply-wait original-message . message-body-args)
   "Reply to a messsage, but wait until we get a response"
 
 (define (<-reply-wait original-message . message-body-args)
   "Reply to a messsage, but wait until we get a response"
-  (wait-maybe-handle-errors
-   (send-message '() (%current-actor)
-                 (message-from original-message) '*reply*
-                 original-message #t message-body-args)))
+  (if (message-needs-reply? original-message)
+      (wait-maybe-handle-errors
+       (send-message '() (%current-actor)
+                     (message-from original-message) '*reply*
+                     original-message #t message-body-args))
+      #f))
 
 (define (<-reply-wait* send-options original-message
                        . message-body-args)
 
 (define (<-reply-wait* send-options original-message
                        . message-body-args)
                          (message-from original-message) '*reply*
                          original-message #t message-body-args)
            send-options))
                          (message-from original-message) '*reply*
                          original-message #t message-body-args)
            send-options))
-  (apply really-send send-options))
+  (when (message-needs-reply? original-message)
+    (apply really-send send-options)))
 
 (define* (wait-maybe-handle-errors message
                                    #:key accept-errors
 
 (define* (wait-maybe-handle-errors message
                                    #:key accept-errors