Last active
June 16, 2025 21:28
-
-
Save MarkoSh/b69d458c2a13e7a5ec49caa005f8bb71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WorkerTimeout { | |
worker = null; | |
constructor(callback, timeout) { | |
const $this = this; | |
const blob = new Blob([`setTimeout(() => postMessage(0), ${timeout});`]); | |
const workerScript = URL.createObjectURL(blob); | |
$this.worker = new Worker(workerScript); | |
$this.worker.onmessage = () => { | |
callback(); | |
$this.worker.terminate(); | |
}; | |
} | |
} | |
const timeout = new WorkerTimeout(callback, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment