Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support releasing/freeing actors #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kmruiz
Copy link
Member

@kmruiz kmruiz commented Jan 21, 2023

Reason / Issue that solves

Right now there is no easy way to free resources of an actor when it's not useful anymore. Releasing actors should allow systems to clean up resources and dematerialise on the given persistence mechanism, if any.

How does it work?

Untitled-2022-12-19-0030

An actor is released by calling the parent actor system with a reference to the actor to release.

system.releaseActor(clock)

The Release Message message will be sent to the actor mailbox, to be processed. This guarantees that all received messages before the release message are processed in order.

Once the message is consumed by the actor, materialisers are notified on onBeforeRelease, so they can prepare any clean up, if necessary.

Once all materialisers are notified (async), the actor system unsubscribes the actor from all mailboxes and topics. Then, the actor notifies for one last time the materialisers on onAfterRelease. For example, if we store the information in the browser local storage or on a database, onAfterRelease would be a good entrypoint to clean up resources.

Released actors that receive messages will discard the message and throw an exception. The exception contains a field isActorReleased that should be true if the cause is the release of an actor. Also contains a getMessage method with a human-readable explanation.

Breaking Changes

Two new methods in the materialisers that are mandatory:

onBeforeRelease(actor: Actor): void
onAfterRelease(actor: Actor): void

@kmruiz kmruiz added the help wanted Extra attention is needed label Jan 21, 2023
@kmruiz kmruiz self-assigned this Jan 21, 2023
@alvarolorentedev
Copy link
Member

alvarolorentedev commented Jan 23, 2023

@kmruiz we are breaking backwards compatibility with this, right?
I am curious if we should pack this as a beta and have a conversation of other breaking changes we want to bring in tarant.

@kmruiz
Copy link
Member Author

kmruiz commented Jan 23, 2023

We are if we decide that all materialisers must implement the two new functions. However, we could decide to make them optional and maintain compatibility with older versions.

I agree however having a call and discuss next steps ♥️.

@alvarolorentedev
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants