Added a shutdown() method which should stop tristanable and eventy, along with stopping the tasky main loop

This commit is contained in:
Tristan B. Velloza Kildaire 2022-04-07 10:18:54 +02:00
parent bcdc6121ca
commit 16ae65937a
3 changed files with 29 additions and 4 deletions

View File

@ -5,7 +5,7 @@
"copyright": "Copyright © 2021, Tristan B. Kildaire",
"dependencies": {
"bformat": "~>3.1.3",
"eventy": "0.2.1",
"eventy": "0.2.2",
"tristanable": "2.3.14"
},
"description": "Tagged network-message task engine",

View File

@ -2,7 +2,7 @@
"fileVersion": 1,
"versions": {
"bformat": "3.1.3",
"eventy": "0.2.1",
"eventy": "0.2.2",
"tristanable": "2.3.14"
}
}

View File

@ -26,6 +26,8 @@ public final class Engine : Thread
*/
private EvEngine evEngine;
private bool running;
this(Socket socket)
{
/* Set the worker function */
@ -41,6 +43,7 @@ public final class Engine : Thread
tmanager = new Manager(socket);
/* Start the loop */
running = true;
start();
}
@ -62,7 +65,7 @@ public final class Engine : Thread
*/
private void worker()
{
while(true)
while(running)
{
/**
* Loop through each queue, poll for
@ -96,6 +99,21 @@ public final class Engine : Thread
}
}
/**
* Stop the task engine
*/
public void shutdown()
{
/* Stop the loop */
running = false;
/* TODO: Stop tristsnable (must be implemented in tristanable first) */
tmanager.shutdown();
/* TODO: Stop eventy (mjst be implemented in eventy first) */
evEngine.shutdown();
}
/**
* Register a Descriptor with tasky
*/
@ -125,6 +143,8 @@ public final class Engine : Thread
import std.string : cmp;
import std.datetime.stopwatch : StopWatch;
bool runDone;
/* Job type */
Descriptor jobType = new class Descriptor {
public override void handler(Event e)
@ -213,7 +233,7 @@ public final class Engine : Thread
writeln("Server send 4: ", clientSocket.send(encodeForSend(dMesg)));
while(true)
while(!runDone)
{
}
@ -245,10 +265,15 @@ public final class Engine : Thread
{
if(watch.peek() > dur!("seconds")(4))
{
runDone = true;
assert(false);
}
}
runDone = true;
/* TODO: Shutdown tasky here (shutdown eventy and tristanable) */
e.shutdown();
}
}