-
-
Save WolfieWerewolf/204a99c6c620b4242f28caf92c603f34 to your computer and use it in GitHub Desktop.
WebWorker example using importScript
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
Webworker | |
// worker.js | |
var ju; | |
addEventListener('message', function(e) { | |
if (e.data == "dummy") { | |
importScripts('./JapaneseUtil.js'); | |
console.log("this worker on message...", e); | |
if (!ju) ju = JapaneseUtil(); | |
let arr = ju.separate("私は、日本語が得意です。"); | |
postMessage(arr); | |
} | |
}, false); | |
// main.js | |
var worker; | |
document.querySelector("#btn3").onclick = function() { | |
if(!worker) { | |
worker = new Worker("worker.js"); | |
worker.onmessage = function (e) { | |
console.log("e", e); | |
} | |
} | |
worker.postMessage("dummy"); // Start the worker. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment