From 46e5922dc8c311f85426ecca45c71533a49547fc Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 12 Jul 2017 11:12:10 -0400 Subject: [PATCH] Stop a new facet with no endpoints. Fixes #18. --- racket/syndicate/actor.rkt | 4 +++- racket/syndicate/examples/actor/vacuous-facet.rkt | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 racket/syndicate/examples/actor/vacuous-facet.rkt 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")))