From df7f731218c56a25cda01c426cee03c730e3fbea Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 16 Jan 2022 15:16:13 +0200 Subject: [PATCH] Upgraded to new Eventy, integrated Eventy Signal\(\) into Descriptor --- dub.json | 4 ++-- source/tasky/jobs.d | 54 +++++++++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/dub.json b/dub.json index 51ce8d9..90e48cb 100644 --- a/dub.json +++ b/dub.json @@ -5,11 +5,11 @@ "copyright": "Copyright © 2021, Tristan B. Kildaire", "dependencies": { "bformat": "~>3.1.3", - "eventy": "0.1.4", + "eventy": "0.2.1", "tristanable": "2.3.13" }, "description": "Tagged network-message task engine", "license": "LGPL v3", "name": "tasky", "targetType": "library" -} \ No newline at end of file +} diff --git a/source/tasky/jobs.d b/source/tasky/jobs.d index 5bf5b4e..2c2c850 100644 --- a/source/tasky/jobs.d +++ b/source/tasky/jobs.d @@ -17,6 +17,8 @@ import std.container.dlist; import core.sync.mutex : Mutex; import std.string : cmp; +import eventy.signal : Signal; +import eventy.event : Event; /** * A Job to be scheduled @@ -75,23 +77,24 @@ public final class JobException : TaskyException /** * Descriptor * -* This represents a type of Job, complete -* with the data to be sent and a type ID +* This represents a type of Job, represented +* by a unique ID. Along with this is an associated +* signal handler provided by the user which is +* to be run on completion of said Job */ -public abstract class Descriptor +public abstract class Descriptor : Signal { private static __gshared Mutex descQueueLock; private static __gshared DList!(ulong) descQueue; - import eventy.signal; - /** * Descriptor data * * The signal handler that handles the running * of any job associated with this Descriptor + * + * We should `alias can we? */ - private immutable Signal signalHandler; private immutable ulong descriptorClass; /** @@ -230,7 +233,7 @@ public abstract class Descriptor /** * Creates a new Descriptor */ - this(EventHandler ev) + this() { /* Grab a descripor ID */ descriptorClass = addDescQueue(); @@ -240,29 +243,41 @@ public abstract class Descriptor * which handles only the typeID * of `descriptorClass` */ - signalHandler = cast(immutable Signal)new Signal([descriptorClass], ev); + super([descriptorClass]); + + + + + /* TODO: Register `signalHandler` with the Engine */ + /* TODO: Add a queue to the Engine for this desc class ID */ } - /** - * Test creation of a new Descriptor - */ + unittest { + + try { - /* TODO: Set a mock event handler here */ - EventHandler ev; - class TestDesc : Descriptor + /** + * Create a uniqye Descriptor for a future + * Job that will run the function `test` + * on completion (reply) + */ + class DescTest : Descriptor { this() { - /* Set the signal handling funciton */ - super(ev); + handler(null); } + + + public override void handler(Event) {} + } - new TestDesc(); + new DescTest(); assert(true); } @@ -297,6 +312,11 @@ public abstract class Descriptor { return descriptorClass; } + + /** + * Override this to handle Event + */ + public abstract override void handler(Event e); }