Created
April 28, 2021 05:29
-
-
Save yuchenQ/535c0956cfb3dc06de73edffc298744f to your computer and use it in GitHub Desktop.
initWorker
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
const initWorker = (workerFn) => { | |
const iife = `(${workerFn.toString()})()`; | |
const blob = new Blob([iife], { type: 'text/javascript' }); | |
const fileURL = URL.createObjectURL(blob); | |
const worker = new Worker(fileURL); | |
worker.cleanup = () => { | |
URL.revokeObjectURL(fileURL); | |
worker.terminate(); | |
}; | |
return worker; | |
}; | |
export default initWorker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment