Skip to content

Instantly share code, notes, and snippets.

@jgranick
Created August 24, 2012 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgranick/3452902 to your computer and use it in GitHub Desktop.
Save jgranick/3452902 to your computer and use it in GitHub Desktop.
How to send messages between child threads (NME recipe)
import cpp.vm.Thread;
import nme.display.Sprite;
import nme.Lib;
class ThreadingExample extends Sprite {
public function new () {
super ();
var first = Thread.create (onePlusOne);
var second = Thread.create (process);
first.sendMessage (second);
trace ("This message will not wait for the result");
}
private function onePlusOne ():Void {
var second = Thread.readMessage (true);
second.sendMessage (1 + 1);
}
private function process ():Void {
trace ("One plus one equals " + Thread.readMessage (true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment