mirror of https://github.com/deavmi/tasky.git
Upgraded to new Eventy, integrated Eventy Signal\(\) into Descriptor
This commit is contained in:
parent
2712585684
commit
df7f731218
4
dub.json
4
dub.json
|
@ -5,11 +5,11 @@
|
||||||
"copyright": "Copyright © 2021, Tristan B. Kildaire",
|
"copyright": "Copyright © 2021, Tristan B. Kildaire",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bformat": "~>3.1.3",
|
"bformat": "~>3.1.3",
|
||||||
"eventy": "0.1.4",
|
"eventy": "0.2.1",
|
||||||
"tristanable": "2.3.13"
|
"tristanable": "2.3.13"
|
||||||
},
|
},
|
||||||
"description": "Tagged network-message task engine",
|
"description": "Tagged network-message task engine",
|
||||||
"license": "LGPL v3",
|
"license": "LGPL v3",
|
||||||
"name": "tasky",
|
"name": "tasky",
|
||||||
"targetType": "library"
|
"targetType": "library"
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import std.container.dlist;
|
||||||
import core.sync.mutex : Mutex;
|
import core.sync.mutex : Mutex;
|
||||||
|
|
||||||
import std.string : cmp;
|
import std.string : cmp;
|
||||||
|
import eventy.signal : Signal;
|
||||||
|
import eventy.event : Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Job to be scheduled
|
* A Job to be scheduled
|
||||||
|
@ -75,23 +77,24 @@ public final class JobException : TaskyException
|
||||||
/**
|
/**
|
||||||
* Descriptor
|
* Descriptor
|
||||||
*
|
*
|
||||||
* This represents a type of Job, complete
|
* This represents a type of Job, represented
|
||||||
* with the data to be sent and a type ID
|
* 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 Mutex descQueueLock;
|
||||||
private static __gshared DList!(ulong) descQueue;
|
private static __gshared DList!(ulong) descQueue;
|
||||||
|
|
||||||
import eventy.signal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Descriptor data
|
* Descriptor data
|
||||||
*
|
*
|
||||||
* The signal handler that handles the running
|
* The signal handler that handles the running
|
||||||
* of any job associated with this Descriptor
|
* of any job associated with this Descriptor
|
||||||
|
*
|
||||||
|
* We should `alias can we?
|
||||||
*/
|
*/
|
||||||
private immutable Signal signalHandler;
|
|
||||||
private immutable ulong descriptorClass;
|
private immutable ulong descriptorClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,7 +233,7 @@ public abstract class Descriptor
|
||||||
/**
|
/**
|
||||||
* Creates a new Descriptor
|
* Creates a new Descriptor
|
||||||
*/
|
*/
|
||||||
this(EventHandler ev)
|
this()
|
||||||
{
|
{
|
||||||
/* Grab a descripor ID */
|
/* Grab a descripor ID */
|
||||||
descriptorClass = addDescQueue();
|
descriptorClass = addDescQueue();
|
||||||
|
@ -240,29 +243,41 @@ public abstract class Descriptor
|
||||||
* which handles only the typeID
|
* which handles only the typeID
|
||||||
* of `descriptorClass`
|
* 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
|
unittest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/* TODO: Set a mock event handler here */
|
/**
|
||||||
EventHandler ev;
|
* Create a uniqye Descriptor for a future
|
||||||
class TestDesc : Descriptor
|
* Job that will run the function `test`
|
||||||
|
* on completion (reply)
|
||||||
|
*/
|
||||||
|
class DescTest : Descriptor
|
||||||
{
|
{
|
||||||
this()
|
this()
|
||||||
{
|
{
|
||||||
/* Set the signal handling funciton */
|
handler(null);
|
||||||
super(ev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void handler(Event) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new TestDesc();
|
new DescTest();
|
||||||
|
|
||||||
assert(true);
|
assert(true);
|
||||||
}
|
}
|
||||||
|
@ -297,6 +312,11 @@ public abstract class Descriptor
|
||||||
{
|
{
|
||||||
return descriptorClass;
|
return descriptorClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override this to handle Event
|
||||||
|
*/
|
||||||
|
public abstract override void handler(Event e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue