35 lines
751 B
Haxe
35 lines
751 B
Haxe
package lib.turtle;
|
|
|
|
import kernel.turtle.TurtleMutex;
|
|
import kernel.ps.ProcessHandle;
|
|
import kernel.ps.IProcess;
|
|
|
|
abstract class TurtleAppBase implements IProcess {
|
|
private var handle:ProcessHandle;
|
|
|
|
private var _initFunc:Void->Void;
|
|
private var _turtleFunc:Void->Void;
|
|
|
|
public function new(initFunc:Null<Void->Void>, turtleFunc:Void->Void) {
|
|
this._initFunc = initFunc;
|
|
this._turtleFunc = turtleFunc;
|
|
}
|
|
|
|
public final function run(handle:ProcessHandle) {
|
|
this.handle = handle;
|
|
|
|
if (!handle.claimTurtleMutex()) {
|
|
handle.writeLine("Failed to claim turtle mutex");
|
|
handle.close();
|
|
}
|
|
|
|
if (this._initFunc != null) {
|
|
this._initFunc();
|
|
}
|
|
|
|
if (this._turtleFunc != null) {
|
|
TurtleMutex.runInTThread(this._turtleFunc);
|
|
}
|
|
}
|
|
}
|