Last active
August 27, 2018 00:41
-
-
Save uupaa/1bc6ccba7281f7d3231ba04686e2a629 to your computer and use it in GitHub Desktop.
WebWorker make by a string.
This file contains 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
<script> | |
const WORKER_RESOURCE = ` | |
self.onmessage = (event) => { | |
debugger; | |
postMessage(event.data + " worker"); // hello worker | |
}`; | |
const blob = new Blob( [ WORKER_RESOURCE ], { type: "application/javascript" } ); | |
const blobURL = URL.createObjectURL(blob); // -> URL.revokeObjectURL(blobURL); | |
const worker = new Worker(blobURL); | |
worker.onmessage = (event) => { // @arg EventObject - { data: "hello worker" } | |
alert('resp: ' + event.data); | |
}; | |
worker.postMessage('hello'); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment