Skip to content

Add stop behaviour to GenServer #22

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

Open
wants to merge 7 commits into
base: stream_listener
Choose a base branch
from

Conversation

juan518munoz
Copy link
Contributor

@juan518munoz juan518munoz commented Jul 4, 2025

Add a CancellationToken to our Actors.

Idea behind is that we can now stop all the running services working around an actor (timers and listeners as of now) when requested, so they are not left hanging.

Note: this PR has no changes to the threads impl due to being no longer maintained, and should only be merged after stream listener PR.

Closes #18

@fedacking fedacking closed this Jul 7, 2025
@fedacking fedacking reopened this Jul 7, 2025
let join_handle = rt::spawn(async move {
let _ = select(
// Timer action is ignored if it was either cancelled or the associated GenServer is no longer running.
let cancel_conditions = select(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice! I like having both, the individual cancellation_token, and the gen_server associated one

@ElFantasma
Copy link
Collaborator

Good work!
I think the cancellation token logic is missing for stream_listener, maybe?

Also, I think that teardown logic should be a more complete workflow:

  • teardown() should not be called explicitly on the handler (as it is now).
  • Instead, teardown() should be called automatically on exiting the GenServer main_loop, either because of an error, or because of normal termination (ie. returning a Stop outbound message on a callback), probably here and here
  • It should in turn call a teardown() function in the GenServer (giving the opportunity to reimplement it as a callback, similar to init() in Trait implementations, to gracefully shutdown it, as well as liberating any resource potentially being held).

Does it make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants