From 16ae65937a791ea49773983c392421fbdc23f342 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Thu, 7 Apr 2022 10:18:54 +0200 Subject: [PATCH] Added a shutdown() method which should stop tristanable and eventy, along with stopping the tasky main loop --- dub.json | 2 +- dub.selections.json | 2 +- source/tasky/engine.d | 29 +++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/dub.json b/dub.json index 758cd64..00c4310 100644 --- a/dub.json +++ b/dub.json @@ -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", diff --git a/dub.selections.json b/dub.selections.json index df7f1e0..4cfc17f 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -2,7 +2,7 @@ "fileVersion": 1, "versions": { "bformat": "3.1.3", - "eventy": "0.2.1", + "eventy": "0.2.2", "tristanable": "2.3.14" } } diff --git a/source/tasky/engine.d b/source/tasky/engine.d index 4ca91d2..eea53e0 100644 --- a/source/tasky/engine.d +++ b/source/tasky/engine.d @@ -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(); } }