diff --git a/targets/wasm_exec.js b/targets/wasm_exec.js index fd4c8a04d4..845456aa14 100644 --- a/targets/wasm_exec.js +++ b/targets/wasm_exec.js @@ -272,7 +272,11 @@ "runtime.sleepTicks": (timeout) => { // Do not sleep, only reactivate the scheduler after the given // timeout, keeping exactly one pending wakeup. - const ms = Number(timeout) / 1e6; + // Round up to a whole millisecond. Some hosts (Cloudflare + // Workers) only advance the clock by a timer's delay rounded + // down to a millisecond, so a fractional remainder would be + // slept again and again without the clock ever moving. + const ms = Math.ceil(Number(timeout) / 1e6); const due = Date.now() + ms; if (this._scheduledWakeup !== undefined) { if (this._scheduledWakeupDue <= due) return;