actors: Add %current-actor parameter.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 15 Dec 2016 16:18:34 +0000 (10:18 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 15 Dec 2016 16:18:34 +0000 (10:18 -0600)
This allows actors which may call out long procedures, such as a web
worker, to still be able to have access their actor so they can send
messages to other actors.

* 8sync/systems/actors.scm (%current-actor): New variable.
  (hive-process-message): Update to parameterize %current-actor.

8sync/systems/actors.scm

index 84a5c2e3c178f168d39b981f90be4ff2b3b609f3..4c9215fc0e49d5dce6b713608a102d03c32824eb 100644 (file)
@@ -36,6 +36,8 @@
             actor-id
             actor-message-handler
 
             actor-id
             actor-message-handler
 
+            %current-actor
+
             ;;; Commenting out the <address> type for now;
             ;;; it may be back when we have better serializers
             ;; <address>
             ;;; Commenting out the <address> type for now;
             ;;; it may be back when we have better serializers
             ;; <address>
   "Render the full actor id as a human-readable string"
   (address->string (actor-id actor)))
 
   "Render the full actor id as a human-readable string"
   (address->string (actor-id actor)))
 
+(define %current-actor
+  (make-parameter #f))
 
 \f
 ;;; Actor utilities
 
 \f
 ;;; Actor utilities
@@ -510,13 +514,14 @@ more compact following syntax:
        (lambda ()
          (define message-handler (actor-message-handler actor))
          ;; @@: Should a more general error handling happen here?
        (lambda ()
          (define message-handler (actor-message-handler actor))
          ;; @@: Should a more general error handling happen here?
-         (let ((result
-                (message-handler actor message)))
-           (maybe-autoreply actor)
-           ;; Returning result allows actors to possibly make a run-request
-           ;; at the end of handling a message.
-           ;; ... We do want that, right?
-           result)))))
+         (parameterize ((%current-actor actor))
+           (let ((result
+                  (message-handler actor message)))
+             (maybe-autoreply actor)
+             ;; Returning result allows actors to possibly make a run-request
+             ;; at the end of handling a message.
+             ;; ... We do want that, right?
+             result))))))
 
   (define (resume-waiting-coroutine)
     (cond
 
   (define (resume-waiting-coroutine)
     (cond