Skip to content

Instantly share code, notes, and snippets.

@tobx
tobx / timeout.js
Created December 27, 2021 13:53
Async version of setTimeout
export class Timeout {
constructor() {
this.timeoutId = 0;
}
clear() {
window.clearTimeout(this.timeoutId);
this.timeoutId = 0;
}
@tobx
tobx / animation.js
Created December 27, 2021 13:40
Async version of requestAnimationFrame and animation loop
export class Frame {
constructor() {
this.requestId = 0;
}
cancel() {
window.cancelAnimationFrame(this.requestId);
this.requestId = 0;
}