Replace setTimeout with requestAnimationFrame #3

Merged
vlw merged 4 commits from refs/pull/3/head into master 2021-12-26 14:07:37 +01:00
vlw commented 2021-12-06 15:41:22 +01:00 (Migrated from codeberg.org)

Monkeydo relies on the highly volatile setTimeout() to chain scheduled tasks. setTimeout() is both susceptible to unannounced thread sleeping and also time drift. I have therefore replaced it with the generally more stable and consistent window.requestAnimationFrame().

This is a refactor and does not change the upstream developer-facing API.

next() has been renamed to tick() and contains the whole event scheduler now.
Any custom implementation calling next() will therefore stop working.

Monkeydo relies on the highly volatile `setTimeout()` to chain scheduled tasks. `setTimeout()` is both susceptible to unannounced [thread sleeping](https://stackoverflow.com/questions/10739835/are-there-any-standards-for-mobile-device-web-browsers-in-terms-of-thread-sleepi/10740558#10740558) and also [time drift](https://stackoverflow.com/questions/985670/will-setinterval-drift). I have therefore replaced it with the generally more stable and consistent [`window.requestAnimationFrame()`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame). This is a refactor and does not change the upstream developer-facing API. `next()` has been renamed to `tick()` and contains the whole event scheduler now. Any custom implementation calling `next()` will therefore stop working.
Commenting is not possible because the repository is archived.
No description provided.