diff --git a/syndicate/actor.rkt b/syndicate/actor.rkt index c3c1561..a52dad1 100644 --- a/syndicate/actor.rkt +++ b/syndicate/actor.rkt @@ -45,6 +45,7 @@ turn-facet! turn-stop! turn-spawn! + turn-stop-actor-system! turn-stop-actor! turn-crash! turn-field! @@ -196,8 +197,8 @@ (thread-wait (engine-thread e))) (define (actor-system-shutdown! e) - (for [(ac (in-list (engine-shutdown! e)))] - (actor-terminate! ac #t))) + (define actors (engine-shutdown! e)) + (for [(ac (in-list actors))] (actor-terminate! ac #t))) (define (escape-pod boot-proc #:name [name 'escape-pod]) (define e (actor-engine (facet-actor (turn-active-facet (current-turn))))) @@ -384,6 +385,10 @@ new-facet)) (define (turn-stop! [f (turn-active-facet (current-turn))] [continuation #f]) + (when (not (eq? (facet-actor f) (facet-actor (turn-active-facet (current-turn))))) + (error 'turn-stop! "Attempted to stop facet ~v from different actor ~v" + f + (facet-actor (turn-active-facet (current-turn))))) (log-syndicate/actor-debug " ENQ stop-facet ~v" f) (turn-enqueue! (current-turn) f @@ -425,6 +430,13 @@ linked-peer link-message handle) (deliver (entity-assert link-entity) link-message handle))))))) +(define (turn-stop-actor-system! turn) + (define ac (facet-actor (turn-active-facet turn))) + (log-syndicate/actor-debug " ENQ stop-actor-system ~v" ac) + (turn-enqueue! turn (actor-root ac) (lambda () + (log-syndicate/actor-debug " DEQ stop-actor-system ~v" ac) + (actor-system-shutdown! (actor-engine ac))))) + (define (turn-stop-actor! turn) (define ac (facet-actor (turn-active-facet turn))) (log-syndicate/actor-debug " ENQ stop-actor ~v" ac) diff --git a/syndicate/syntax.rkt b/syndicate/syntax.rkt index 234f35f..34bdf57 100644 --- a/syndicate/syntax.rkt +++ b/syndicate/syntax.rkt @@ -16,6 +16,7 @@ react let-event define-field + stop-actor-system stop-facet stop-current-facet on-start @@ -191,6 +192,9 @@ (define-syntax-rule (define-field id initial-value) (define id (turn-field! this-turn 'id initial-value))) +(define (stop-actor-system) + (turn-stop-actor-system! this-turn)) + (define-syntax stop-facet (syntax-rules () [(_ f) (turn-stop! f)]