From fbf1ef6e72e052ee3ca5f83d8b9dc72eee3a623b Mon Sep 17 00:00:00 2001 From: jtnunley Date: Fri, 25 Nov 2022 14:13:18 -0800 Subject: [PATCH] Round up ms timeout --- src/utils.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index d1b49727..ab451a66 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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)) } }