Skip to content

Commit

Permalink
fix #495: VM emulator ignores Sys.wait
Browse files Browse the repository at this point in the history
use javascript setTimeout instead of busy wait loop
  • Loading branch information
Dorian Ignee committed Dec 10, 2024
1 parent 36e768d commit 3d44ae7
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions simulator/src/vm/os/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,13 @@ export class SysLib {
this.error(ERRNO.SYS_WAIT_DURATION_NOT_POSITIVE);
return;
}
this.block();

let waited = 0;

const loop = (delta: number) => {
if (this.cancelWait) {
return;
}

waited += delta;

if (waited >= ms) {
this.release();
} else {
this.animationFrameId = requestAnimationFrame(loop);
}
};
this.block();

loop(0);
(async () => {
await new Promise(x => setTimeout(x, ms));
this.release();
})();
}

halt() {
Expand Down

0 comments on commit 3d44ae7

Please sign in to comment.