Skip to content

Instantly share code, notes, and snippets.

@ruby0x1
Last active January 1, 2016 02:29
Show Gist options
  • Save ruby0x1/8079431 to your computer and use it in GitHub Desktop.
Save ruby0x1/8079431 to your computer and use it in GitHub Desktop.
golems test
import net.rezmason.utils.workers.BasicWorker;
import net.rezmason.utils.workers.BasicBoss;
class SimpleExample {
public static function main() {
var start = haxe.Timer.stamp();
var do_loop = true;
var boss : BossExample<Int,String> = null;
var last:Int = 0;
var now:Int = 0;
while(do_loop) {
//> 2 seconds in, create a worker
if(haxe.Timer.stamp() > (start+2)) {
if(boss == null) {
trace("Starting boss!");
boss = new BossExample<Int,String>( WorkerExample );
boss.start();
}
}
if(haxe.Timer.stamp() > (start+5)) {
do_loop = false;
}
now = Std.int(haxe.Timer.stamp() - start);
if(now != last) {
trace( now );
last = now;
}
}
trace("done");
}
}
class BossExample<Int,String> extends BasicBoss<Int,String> {
override function receive(data:String) {
trace("Boss receive data : " + data);
}
}
class WorkerExample extends BasicWorker<Int,String> {
override function receive(data:Int):Void {
try {
var last:Int = 0;
var now:Int = 0;
send("worker started");
var start = haxe.Timer.stamp();
var do_loop = true;
while(do_loop) {
if(haxe.Timer.stamp() > (start+2)) {
do_loop = false;
}
now = Std.int(haxe.Timer.stamp() - start);
if(now != last) {
send( ">> wrk " + now );
last = now;
}
}
send("background worker done");
} catch(e:Dynamic) {
sendError(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment