X-Git-Url: https://jxself.org/git/?p=8sync.git;a=blobdiff_plain;f=8sync%2Fsystems%2Factors.scm;h=51a6e50c88abfee680426b3356d2b159f0e00882;hp=ce55597bf912aa001282e65cbac055c872a7b991;hb=24964693f8dfc06f75d706acc3255d0686458ce8;hpb=674056fde0ebfc4454485a8776ecb9efd9c3af8f diff --git a/8sync/systems/actors.scm b/8sync/systems/actors.scm index ce55597..51a6e50 100644 --- a/8sync/systems/actors.scm +++ b/8sync/systems/actors.scm @@ -171,6 +171,13 @@ If key not found and DFLT not provided, throw an error." dflt)))) +(define (message-needs-reply message) + "See if this message needs a reply still" + (and (message-wants-reply message) + (not (or (message-replied message) + (message-deferred-reply message))))) + + (define (kwarg-list-to-alist args) (let loop ((remaining args) (result '())) @@ -378,6 +385,7 @@ more compact following syntax: ;; This is a map from cons cell of message-id ;; to a cons cell of (actor-id . coroutine) ;; @@: Should we have a record type? + ;; @@: Should there be any way to clear out "old" coroutines? (waiting-coroutines #:init-thunk make-hash-table #:getter hive-waiting-coroutines) ;; Message prompt @@ -450,7 +458,17 @@ more compact following syntax: (lambda () (define message-handler (actor-message-handler actor)) ;; @@: Should a more general error handling happen here? - (message-handler actor message)) + (let ((result + (message-handler actor message))) + ;; Possibly autoreply + (if (message-needs-reply message) + ;; @@: Should we give *autoreply* as the action instead of *reply*? + (reply-message actor message + #:*auto-reply* #t)) + ;; Returning result allows actors to possibly make a run-request + ;; at the end of handling a message. + ;; ... We do want that, right? + result)) (lambda (kont actor message) (let ((hive (actor-hive actor))) @@ -464,7 +482,14 @@ more compact following syntax: (define (resume-waiting-coroutine) (match (hash-remove! (hive-waiting-coroutines hive) (message-in-reply-to message)) - ((_ . kont) + ((_ . (resume-actor-id . kont)) + (if (not (equal? (message-to message) + resume-actor-id)) + (throw 'resuming-to-wrong-actor + "Attempted to resume a coroutine to the wrong actor!" + #:expected-actor-id (message-to message) + #:got-actor-id resume-actor-id + #:message message)) (kont message)) (#f (throw 'no-waiting-coroutine "message in-reply-to tries to resume nonexistent coroutine"