diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2021-06-15 14:18:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 14:18:16 -0400 |
commit | 0c0058f1181d1fd6590f760a0375ead706043d32 (patch) | |
tree | 3eba38c407fd2c9bf5ca26d741bb61e0fae8e9b7 | |
parent | 9c42b5e03b6500aaf38b37b208ad9ae1ba2bbaf3 (diff) |
fix: set minimum timeout to be 4 milliseconds (#10972)
-rw-r--r-- | extensions/timers/lib.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/extensions/timers/lib.rs b/extensions/timers/lib.rs index 43a40e939..5f65ae3ef 100644 --- a/extensions/timers/lib.rs +++ b/extensions/timers/lib.rs @@ -122,6 +122,12 @@ pub fn op_global_timer_start( timeout: u64, _: (), ) -> Result<(), AnyError> { + // According to spec, minimum allowed timeout is 4 ms. + // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers + // TODO(#10974) Per spec this is actually a little more complicated than this. + // The minimum timeout depends on the nesting level of the timeout. + let timeout = std::cmp::max(timeout, 4); + let deadline = Instant::now() + Duration::from_millis(timeout); let global_timer = state.borrow_mut::<GlobalTimer>(); global_timer.new_timeout(deadline); |