Skip to content

Instantly share code, notes, and snippets.

@Blezzoh
Last active November 25, 2019 18:26
Show Gist options
  • Save Blezzoh/b193ead79b50c3723e423752ce27aa86 to your computer and use it in GitHub Desktop.
Save Blezzoh/b193ead79b50c3723e423752ce27aa86 to your computer and use it in GitHub Desktop.
worker set up
export default class WebWorker {
constructor(worker) {
const code = worker.toString();
// converting the code to a blob
const blob = new Blob(["(" + code + ")()"]);
// url for the blob
const blobUrl = URL.createObjectURL(blob)
// worker set up
this.worker = new Worker(blobUrl);
return this.worker
}
// will be called to terminate the worker
terminate (){
this.worker.terminate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment