Created
July 5, 2022 16:10
-
-
Save zazaulola/939809b49576c2b22c8fd8a79c87b2be 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
function createWorker(callable) { | |
const code = `onmessage=${callable.toString()}`; | |
const blob = new Blob([code], { type: 'text/javascript' }); | |
const url = URL.createObjectURL(blob); | |
const worker = new Worker(url); | |
URL.revokeObjectURL(url); | |
return worker; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment