diff options
| author | Zeyla Hellyer <[email protected]> | 2017-09-30 16:07:40 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-09-30 16:08:12 -0700 |
| commit | 683691f762bbf58e3abf3bc67381e18112f5c8ad (patch) | |
| tree | c29424f0f264912ab99ee31ae718a93fadd30143 /src/gateway/mod.rs | |
| parent | Improve shard and shard runner logging (diff) | |
| download | serenity-683691f762bbf58e3abf3bc67381e18112f5c8ad.tar.xz serenity-683691f762bbf58e3abf3bc67381e18112f5c8ad.zip | |
Improve shard logic
Improve shard logic by more cleanly differentiating when resuming, as
well as actually fixing resume logic.
For shard runners, better handling of dead clients is added, as well as
more use of the shard manager, in that the runner will now more
liberally request a restart when required (instead of sitting and doing
nothing infinitely).
Diffstat (limited to 'src/gateway/mod.rs')
| -rw-r--r-- | src/gateway/mod.rs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index 6f839db..bd9c45b 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -60,7 +60,7 @@ pub use self::shard::Shard; /// This can be useful for knowing which shards are currently "down"/"up". /// /// [`Shard`]: struct.Shard.html -#[derive(Debug, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] pub enum ConnectionStage { /// Indicator that the [`Shard`] is normally connected and is not in, e.g., /// a resume phase. @@ -83,5 +83,56 @@ pub enum ConnectionStage { Handshake, /// Indicator that the [`Shard`] has sent an IDENTIFY packet and is awaiting /// a READY packet. + /// + /// [`Shard`]: struct.Shard.html Identifying, + /// Indicator that the [`Shard`] has sent a RESUME packet and is awaiting a + /// RESUMED packet. + /// + /// [`Shard`]: struct.Shard.html + Resuming, +} + +impl ConnectionStage { + /// Whether the stage is a form of connecting. + /// + /// This will return `true` on: + /// + /// - [`Connecting`][`ConnectionStage::Connecting`] + /// - [`Handshake`][`ConnectionStage::Handshake`] + /// - [`Identifying`][`ConnectionStage::Identifying`] + /// - [`Resuming`][`ConnectionStage::Resuming`] + /// + /// All other variants will return `false`. + /// + /// # Examples + /// + /// Assert that [`ConnectionStage::Identifying`] is a connecting stage: + /// + /// ```rust + /// use serenity::gateway::ConnectionStage; + /// + /// assert!(ConnectionStage::Identifying.is_connecting()); + /// ``` + /// + /// Assert that [`ConnectionStage::Connected`] is _not_ a connecting stage: + /// + /// ```rust + /// use serenity::gateway::ConnectionStage; + /// + /// assert!(!ConnectionStage::Connected.is_connecting()); + /// ``` + /// + /// [`ConnectionStage::Connecting`]: #variant.Connecting + /// [`ConnectionStage::Handshake`]: #variant.Handshake + /// [`ConnectionStage::Identifying`]: #variant.Identifying + /// [`ConnectionStage::Resuming`]: #variant.Resuming + pub fn is_connecting(&self) -> bool { + use self::ConnectionStage::*; + + *self == Connecting + || *self == Handshake + || *self == Identifying + || *self == Resuming + } } |