2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-30 17:25:32 +00:00

Merge pull request #1044 from notgull/timeout_roundup

Round up timeout to the nearest millisecond for WASM
This commit is contained in:
Josh Triplett 2023-05-01 00:53:53 +09:00 committed by GitHub
commit 1855e858e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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))
}
}