Skip to content

Commit

Permalink
Compare Instants in Shard::latency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Zeyla Hellyer committed Jan 6, 2018
1 parent 85d7d5f commit 08db9fa
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/gateway/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 08db9fa

Please sign in to comment.