1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix: set minimum timeout to be 4 milliseconds (#10972)

This commit is contained in:
Ryan Dahl 2021-06-15 14:18:16 -04:00 committed by GitHub
parent 9c42b5e03b
commit 0c0058f118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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