Last active
August 7, 2019 16:19
-
-
Save cambiata/be0c2dc499da4be71151 to your computer and use it in GitHub Desktop.
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
-cp src | |
-js bin/Test.js | |
-main Test |
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
-cp src | |
-js bin/WorkerScript.js | |
WorkerScript |
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
Haxe Web Worker example based on David Mouton's code from this thread: | |
https://groups.google.com/d/msg/haxelang/id97u-SIGA0/snfI9hBJNkQJ | |
Compiles with Haxe 3.2 |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Workers2</title> | |
<meta name="description" content="" /> | |
</head> | |
<body> | |
<p>Check the console for output!</p> | |
<script src="Test.js"></script> | |
</body> | |
</html> |
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
package; | |
class Test | |
{ | |
static function main() | |
{ | |
var worker = new js.html.Worker('WorkerScript.js'); | |
worker.onmessage = function(e) { | |
trace('Message from worker: ' + e.data); | |
} | |
worker.postMessage('Start'); | |
worker.postMessage(123); | |
worker.postMessage('Hello'); | |
worker.postMessage({name:'Bob'}); | |
} | |
} |
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
package; | |
class WorkerScript | |
{ | |
public static function __init__() { | |
untyped __js__("onmessage = WorkerScript.prototype.messageHandler"); | |
} | |
public function messageHandler(event) { | |
switch event.data { | |
// Do whatever... | |
// Here, for testing, we simply bounce back the data we got... | |
case _: postMessage(event.data); | |
} | |
} | |
// The following line seems to be needed only by the compiler... | |
public function postMessage(message) {} | |
} |
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
// This is the compiled output of WorkerScript.hx, built with >haxe build-worker-script.hxml | |
(function (console) { "use strict"; | |
var WorkerScript = function() { }; | |
WorkerScript.prototype = { | |
messageHandler: function(event) { | |
var _g = event.data; | |
this.postMessage(event.data); | |
} | |
,postMessage: function(message) { | |
} | |
}; | |
onmessage = WorkerScript.prototype.messageHandler; | |
})(typeof console != "undefined" ? console : {log:function(){}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wanted to suggest fixing the
WorkerScript
which is working "by chance" only:Also the magic
__init__
could be replaced by a regular-main
.