added example excavate app
This commit is contained in:
17
src/lib/turtle/Helper.hx
Normal file
17
src/lib/turtle/Helper.hx
Normal file
@@ -0,0 +1,17 @@
|
||||
package lib.turtle;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class Helper {
|
||||
public static function times(func:Void->Outcome<Noise, String>, times:Int):Outcome<Noise, {step:Int, error:String}> {
|
||||
for (i in 0...times) {
|
||||
switch (func()) {
|
||||
case Success(_):
|
||||
case Failure(err):
|
||||
return Failure({step: i, error: err});
|
||||
}
|
||||
}
|
||||
|
||||
return Success(null);
|
||||
}
|
||||
}
|
||||
34
src/lib/turtle/TurtleAppBase.hx
Normal file
34
src/lib/turtle/TurtleAppBase.hx
Normal file
@@ -0,0 +1,34 @@
|
||||
package lib.turtle;
|
||||
|
||||
import kernel.turtle.TurtleMutex;
|
||||
import kernel.ps.ProcessHandle;
|
||||
import kernel.ps.Process;
|
||||
|
||||
abstract class TurtleAppBase implements Process {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user