Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implement a basic shutdown mechanism for an actor. Essentially actors are spawned by parent actors and while they can continue to exist forever (lifetime of the process), they often have lifetimes associated with them.
I'm defining basic shutdown support as:
Additional functionality that should exist as part of actor shut-down, but are a stretch goal of this work:
Shutdown Semantics and Message Draining
Actors are single-threaded and process messages from their mailbox serially. So the natural question is, when shutting down, how are existing and incoming messages handled? The answer is that there are two (related) shutdown paths, immediate shutdown and delayed shutdown.
Immediate shutdown is what it sounds like. All messages in the queue are left un-processed, the actor's shutdown hook is called, the actor is removed from the executor, and all death-watches are triggered.
Delayed shutdown is done through the use of a poison pill. This is a special message that can be sent to the actor and sits in the mailbox (message queue) like any other message. What makes it special is that once the poison pill message is processed, the actor's immedaite shutdown logic is triggered. By triggering this code-path through a normal message, all existing messages are processed first (drained) before the actor is terminated. Although it's still possible other messages will be queued up after the poison pill message.
All of the unprocessed messages will go to the dead-letter queue. Actors who's messages are dropped will not receive any sort of notification as message delivery is at-most-once semantics.
Motivation
Like objects in OOP, threads, or processes - actors need the ability both to be spawned and to be terminated.
Test Plan
TBD