you can stop the turtle thread now
This commit is contained in:
parent
a46760e587
commit
21387cd8e7
@ -97,6 +97,7 @@ class KernelEvents {
|
||||
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
||||
|
||||
private static var stopLoop:Bool = false;
|
||||
private static var turtleCoroutine:Coroutine<Dynamic>;
|
||||
|
||||
@:allow(kernel.Init)
|
||||
private static function init() {
|
||||
@ -144,15 +145,19 @@ class KernelEvents {
|
||||
}
|
||||
}
|
||||
|
||||
private static function turtleLoop() {
|
||||
var turtleCoroutine = Coroutine.create(runTurtleLoop);
|
||||
@:allow(kernel.turtle.TurtleMutex)
|
||||
private static function startTurtleCoroutine() {
|
||||
turtleCoroutine = Coroutine.create(runTurtleLoop);
|
||||
Coroutine.resume(turtleCoroutine);
|
||||
}
|
||||
|
||||
private static function turtleLoop() {
|
||||
startTurtleCoroutine();
|
||||
|
||||
while (true) {
|
||||
var eventData = pullEvents();
|
||||
|
||||
if (eventData[1] == "turtle_response" || eventData[1] == "tthread") {
|
||||
Log.debug('Resuming turtle thread');
|
||||
var result = Coroutine.resume(turtleCoroutine, TableTools.unpack(eventData));
|
||||
|
||||
if (!result.success) {
|
||||
@ -170,7 +175,9 @@ class KernelEvents {
|
||||
|
||||
private static function runTurtleLoop() {
|
||||
while (!stopLoop) {
|
||||
Coroutine.yield();
|
||||
if ((TableTools.pack(Coroutine.yield()))[1] != "tthread")
|
||||
continue;
|
||||
|
||||
if (stopLoop)
|
||||
continue;
|
||||
TurtleMutex.runThreadFunc();
|
||||
|
@ -43,4 +43,9 @@ class TurtleMutex {
|
||||
threadFunc = func;
|
||||
OS.queueEvent("tthread");
|
||||
}
|
||||
|
||||
public static function stopTurtleThread() {
|
||||
threadFunc = null;
|
||||
KernelEvents.startTurtleCoroutine();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user