Created
December 25, 2017 07:03
-
-
Save seiroise/e4d5b00bf095b46f02fe6808ad75cfcb to your computer and use it in GitHub Desktop.
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
| var MyModule = {}; | |
| MyModule.Webworkertest = pc.createScript('webworkertest'); | |
| MyModule.Webworkertest.prototype.initialize = function() { | |
| if(window.Worker) { | |
| var htmlAsset; | |
| htmlAsset = this.app.assets.find('test.worker.html'); | |
| var div = document.createElement('div'); | |
| div.style.display = "none"; | |
| div.innerHTML = htmlAsset.resource; | |
| document.body.appendChild(div); | |
| var source = document.getElementById("worker").textContent; | |
| var blob = new Blob([source], {type:"text/javascript"}); | |
| document.body.removeChild(div); | |
| this.worker = new Worker(window.URL.createObjectURL(blob)); | |
| this.worker.onmessage = function(e) { | |
| var result = e.data; | |
| console.log("from worker: " + result); | |
| }; | |
| this.worker.onerror = function(e) { | |
| console.log(e); | |
| }; | |
| var data = { | |
| name: "hello", | |
| age: 19 | |
| }; | |
| this.worker.postMessage(data); | |
| } | |
| }; | |
| MyModule.Webworkertest.prototype.update = function(dt) { | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment