Last active
November 25, 2019 18:26
-
-
Save Blezzoh/b193ead79b50c3723e423752ce27aa86 to your computer and use it in GitHub Desktop.
worker set up
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
| 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