Created
November 16, 2012 10:19
-
-
Save clemos/4086201 to your computer and use it in GitHub Desktop.
Javascript Workers in Haxe
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
-main MyWorkerScript | |
-js myworkerscript.js | |
--next | |
-main MyWorkerTest | |
-js myworkertest.js |
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
using WorkerScript; | |
class MyWorkerScript extends WorkerScript { | |
public override function onMessage(e){ | |
trace("on message triggered"); | |
postMessage("ola"); | |
} | |
static function main(){ | |
new MyWorkerScript().export(); | |
} | |
} |
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
class MyWorkerTest { | |
public static function main(){ | |
var worker = new Worker("myworkerscript.js"); | |
worker.postMessage("coucou"); | |
} | |
} |
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
@:native("Worker") | |
extern class Worker { | |
public function new( script : String ) : Void; | |
public function postMessage( m : Dynamic ) : Void; | |
public function addEventListener( type : Dynamic , cb : Dynamic -> Void ) : Void; | |
} |
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
class WorkerScript { | |
public function new(){} | |
public function onMessage( e : Dynamic ) : Void { } | |
public inline function postMessage( m : Dynamic ) : Void { | |
untyped __js__("self.postMessage( m )"); | |
} | |
public static function export( script : WorkerScript ){ | |
untyped __js__("self.onmessage = script.onMessage"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment