Skip to content

Commit

Permalink
Merge pull request #1044 from notgull/timeout_roundup
Browse files Browse the repository at this point in the history
Round up timeout to the nearest millisecond for WASM
  • Loading branch information
joshtriplett authored Apr 30, 2023
2 parents ef6ebb1 + fbf1ef6 commit 1855e85
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ mod timer {

impl Timer {
pub(crate) fn after(dur: std::time::Duration) -> Self {
Timer(TimeoutFuture::new(dur.as_millis() as u32))
// Round up to the nearest millisecond.
let mut timeout_ms = dur.as_millis() as u32;
if std::time::Duration::from_millis(timeout_ms as u64) < dur {
timeout_ms += 1;
}

Timer(TimeoutFuture::new(timeout_ms))
}
}

Expand Down

0 comments on commit 1855e85

Please sign in to comment.