From: Christopher Allan Webber Date: Fri, 20 Jan 2017 23:58:20 +0000 (-0600) Subject: actors: Don't reply to a message when the messsage doesn't need a reply. X-Git-Tag: v0.4.2~15 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=2aab08f137540cf22d5f5e32467e838c3ab18637;p=8sync.git actors: Don't reply to a message when the messsage doesn't need a reply. * 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. --- diff --git a/8sync/actors.scm b/8sync/actors.scm index c805067..04e1c06 100644 --- a/8sync/actors.scm +++ b/8sync/actors.scm @@ -233,8 +233,9 @@ (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" @@ -243,7 +244,8 @@ (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!" @@ -252,10 +254,12 @@ (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) @@ -267,7 +271,8 @@ (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