-
Notifications
You must be signed in to change notification settings - Fork 628
Implement ShardManager::get_shutdown_trigger #3353
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
Conversation
|
Doesn't |
|
Nope, what about shutting down the bot cleanly on control C? |
Do you mean shutting down the bot from within a signal handler? |
0c1716a to
a5a1436
Compare
3d3a833 to
94dc7ca
Compare
| /// Retrieves a function which can be used to shut down the ShardManager later. | ||
| /// | ||
| /// This function will return `true` if the ShardManager has successfully been | ||
| /// notified to shut down, or false if it has already shut down and been dropped. | ||
| pub fn get_shutdown_trigger(&self) -> impl FnOnce() -> bool + Send + use<> { | ||
| let manager_tx = self.manager_tx.clone(); | ||
| move || manager_tx.unbounded_send(ShardManagerMessage::Quit(Ok(()))).is_ok() | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think exposing self.manager_tx is maybe a more flexible solution? This function kinda sticks out, and I don't really like the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more flexible, but it's exposing too much API to public consumers imo, leading to defensive or defective programming inside the currently quite simple ShardManager. This is the bare minimum interface that users (at least I) need, and future refactors/reworks cannot be merged if they cannot replicate this behavior.
This removes the uncallable public functions on ShardManager after the rework, and adds a
get_shutdown_triggerfunction which allows for shutting the shard manager down after it has been mutably borrowed for the lifetime of the bot.