From 940cf28396a401ff67ca81fb7fe2580b1784a733 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 15 Dec 2016 10:18:34 -0600 Subject: [PATCH] actors: Add %current-actor parameter. 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 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/8sync/systems/actors.scm b/8sync/systems/actors.scm index 84a5c2e..4c9215f 100644 --- a/8sync/systems/actors.scm +++ b/8sync/systems/actors.scm @@ -36,6 +36,8 @@ actor-id actor-message-handler + %current-actor + ;;; Commenting out the
type for now; ;;; it may be back when we have better serializers ;;
@@ -281,6 +283,8 @@ "Render the full actor id as a human-readable string" (address->string (actor-id actor))) +(define %current-actor + (make-parameter #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? - (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 -- 2.31.1