-
Notifications
You must be signed in to change notification settings - Fork 596
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
Remove ShardManagerMonitor and other gateway cleanup #2372
Conversation
dispatch_event was a function that was only ever called inside ShardRunner::run with a ClientEvent argument, which itself is just a single-variant enum that only ever contains a ShardStageUpdateEvent. So, both ClientEvent and dispatch_event are confusing indirections without no clear purpose and I factored them out by inlining the implementation of dispatch_event into ShardRunner::run
It was a single-variant enum that only ever contained ShardClientMessage. Using ShardClientMessage directly is less confusing
From ShardManagerMonitor to ShardManager First step in removing ShardManagerMonitor
The message channel for ShardRunner was actually passing around Shard**Client**Message's instead of ShardRunnerMessage's (ShardClientMessage is an enum over ShardRunnerMessage and ShardManagerMessage). That's because ShardRunner hijacked two of ShardManagerMessage's enum variants for its own purpose (Restart and Shutdown). I moved those two to ShardRunnerMessage. And then replaced ShardClientMessage with ShardRunnerMessage for the ShardRunner channel communication. After that, the only remaining uses of the ShardManagerMessage's enum variants were for communication with ShardManager (bliss!). So I removed the Restart and ShardUpdate variants in favor of executing their logic in ShardManager::{restart, shard_update} directly.
Basically, the only remaining purpose of ShardManagerMonitor was to let Client::start_connection() call it and get the return value back, once ShardManagerMessage::{ShutdownInitiated, ShardInvalidAuthentication, ShardInvalidGatewayIntents, ShardDisallowedGatewayIntents} is received. If we want to inline that code into ShardManager, we need to have a way to get the return value from a ShardManager method call into Client::start_connection. Obvious solution: a channel! So, this commit finally deletes ShardManagerMonitor and replaced the channel to it with a channel for the return value. And Client now stores that channel instead of ShardManagerMonitor and queries it inside start_connection
Will review this later today. Just quickly noticed that the docs CI job is failing. |
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.
I'd say this looks good, aside from a few tiny nits. Untangling the mess that is the gateway code is definitely a good thing (I say this as someone relatively unfamiliar with gateway internals).
Could you provide a sentence or two describing the breaking changes in this PR, for changelog purposes?
Co-authored-by: Michael Krasnitski <[email protected]>
Since you said "a sentence or two":
|
Here is some additional context about the removed types: Removed:
Thanks to @tazz4843 for pointing out the lacking explanation |
Fix issues caused by serenity-rs/serenity#2372 and serenity-rs/serenity#2380. Additionally, this Boxes the TrySendError from Serenity at Clippy's behest (causing a ~330B Result type). --------- Co-authored-by: Kyle Simpson <[email protected]>
Fix issues caused by serenity-rs/serenity#2372 and serenity-rs/serenity#2380. Additionally, this Boxes the TrySendError from Serenity at Clippy's behest (causing a ~330B Result type). --------- Co-authored-by: Kyle Simpson <[email protected]>
The bulk of this PR is removing ShardManagerMonitor. It was just a background task that received ShardManagerMessage's and called the respective ShardManager function. Now, you can just call the respective ShardManager function directly.
The commits about removing ShardManagerMonitor are marked with
[SMM]
. The other commits do other miscellaneous related clean-up. See commit titles and descriptions for more details.Largely untested