diff --git a/racket/syndicate/actor.rkt b/racket/syndicate/actor.rkt index c153940..92f5409 100644 --- a/racket/syndicate/actor.rkt +++ b/racket/syndicate/actor.rkt @@ -990,7 +990,9 @@ (lookup-facet fid) (patch (actor-state-knowledge (current-actor-state)) trie-empty) #t) - (when (and (facet-live? fid) (pair? parent-fid) (not (facet-live? parent-fid))) + (when (and (facet-live? fid) + (or (and (pair? parent-fid) (not (facet-live? parent-fid))) + (hash-empty? (facet-endpoints (lookup-facet fid))))) (terminate-facet! fid))) ;; If the named facet is live, terminate it. diff --git a/racket/syndicate/examples/actor/vacuous-facet.rkt b/racket/syndicate/examples/actor/vacuous-facet.rkt new file mode 100644 index 0000000..41767ad --- /dev/null +++ b/racket/syndicate/examples/actor/vacuous-facet.rkt @@ -0,0 +1,11 @@ +#lang syndicate/actor +;; Demonstrates that facets with no endpoints don't outlive their `add-facet!` call. + +;; This actor will have two facets briefly, before dropping to one: +(spawn (on-start (react (on-start (printf "Hi 1!\n")) + (on-stop (printf "Bye 1!\n")))) + (assert 'x)) + +;; This actor will have one facet briefly, before dropping to zero and terminating: +(spawn (on-start (printf "Hi 2!\n")) + (on-stop (printf "Bye 2!\n")))