diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-06 08:04:35 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-06 08:04:35 -0800 |
| commit | 08db9fa2adef141743ab9681c46dd91489278063 (patch) | |
| tree | 26f2171cd043b264a01302b20eac3ff9406fd064 /src | |
| parent | Further generic-ify `reaction_users` `after` param (diff) | |
| download | serenity-08db9fa2adef141743ab9681c46dd91489278063.tar.xz serenity-08db9fa2adef141743ab9681c46dd91489278063.zip | |
Compare Instants in Shard::latency
When calculating the latency between when a heartbeat was sent and a
heartbeat acknowledgement was received, ensure that the heartbeat
acknowledgement was received after the heartbeat was sent. This avoids a
panic. Otherwise, return None.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gateway/shard.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs index 75dc147..a890029 100644 --- a/src/gateway/shard.rs +++ b/src/gateway/shard.rs @@ -652,11 +652,13 @@ impl Shard { // Shamelessly stolen from brayzure's commit in eris: // <https://github.com/abalabahaha/eris/commit/0ce296ae9a542bcec0edf1c999ee2d9986bed5a6> pub fn latency(&self) -> Option<StdDuration> { - if let (Some(received), Some(sent)) = self.heartbeat_instants { - Some(sent - received) - } else { - None + if let (Some(sent), Some(received)) = self.heartbeat_instants { + if received > sent { + return Some(received - sent); + } } + + None } #[cfg(feature = "voice")] |