From: Christopher Allan Webber Date: Thu, 15 Dec 2016 16:18:34 +0000 (-0600) Subject: actors: Add %current-actor parameter. X-Git-Tag: v0.3.0~8 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=940cf28396a401ff67ca81fb7fe2580b1784a733;p=8sync.git 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. --- 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