aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-01-06 08:04:35 -0800
committerZeyla Hellyer <[email protected]>2018-01-06 08:04:35 -0800
commit08db9fa2adef141743ab9681c46dd91489278063 (patch)
tree26f2171cd043b264a01302b20eac3ff9406fd064 /src
parentFurther generic-ify `reaction_users` `after` param (diff)
downloadserenity-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.rs10
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")]