Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion targets/wasm_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down