Skip to content

Commit

Permalink
Use duration as default when subtracting duration in accurate timer.
Browse files Browse the repository at this point in the history
If the duration subtraction in the accurate timer results in an
overflow, just use the original duration instead of expecting an error.
  • Loading branch information
mdwn committed May 13, 2024
1 parent a0f9676 commit cb9c63f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/midi/midir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,11 @@ impl<T: Timer> Timer for AccurateTimer<T> {
match self.last_instant {
Some(last_instant) => {
self.last_instant = Some(last_instant.add(duration));

// Subtract the duration unless it would be an overflow. If so, use the original duration.
duration = duration
.checked_sub(Instant::now().duration_since(last_instant))
.expect("duration should not be less during subtraction")
.unwrap_or(duration);
}
None => self.last_instant = Some(time::Instant::now()),
};
Expand Down

0 comments on commit cb9c63f

Please sign in to comment.