mirror of https://github.com/deavmi/tasky.git
Compare commits
2 Commits
b0d0b19a4a
...
0b1c8242fd
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 0b1c8242fd | |
Tristan B. Velloza Kildaire | bed096df27 |
4
dub.json
4
dub.json
|
@ -4,9 +4,7 @@
|
|||
],
|
||||
"copyright": "Copyright © 2023, Tristan B. Kildaire",
|
||||
"dependencies": {
|
||||
"bformat": "~>3.1.3",
|
||||
"eventy": "0.2.5",
|
||||
"tristanable": "3.0.1-beta"
|
||||
"tristanable": "3.1.9-beta"
|
||||
},
|
||||
"description": "Tagged network-message task engine",
|
||||
"license": "LGPL v3",
|
||||
|
|
|
@ -1,2 +1,35 @@
|
|||
module tasky.engine;
|
||||
|
||||
import tristanable : Manager, Queue, TaggedMessage;
|
||||
import tasky.request : Request;
|
||||
|
||||
public class Engine
|
||||
{
|
||||
private Manager tManager;
|
||||
|
||||
this(Manager tristanableManager)
|
||||
{
|
||||
this.tManager = tristanableManager;
|
||||
}
|
||||
|
||||
// TODO: Continue working on this
|
||||
|
||||
public void makeRequest(Request req)
|
||||
{
|
||||
/* Get a unique queue */
|
||||
Queue newQueue = tManager.getUniqueQueue();
|
||||
|
||||
/* Create a tagged message with the tag */
|
||||
ulong tag = newQueue.getID();
|
||||
TaggedMessage tReq = new TaggedMessage(tag, req.getRequestData());
|
||||
|
||||
/* Send the message */
|
||||
tManager.sendMessage(tReq);
|
||||
|
||||
/* Await for a response */
|
||||
byte[] resp = newQueue.dequeue().getPayload();
|
||||
|
||||
/* Run the response handler with the response */
|
||||
req.process(resp);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
module tasky;
|
||||
|
||||
public import tasky.engine;
|
||||
public import tasky.engine;
|
||||
public import tasky.request : Request, ResponseHandler;
|
|
@ -0,0 +1,30 @@
|
|||
module tasky.request;
|
||||
|
||||
import tristanable.encoding : TaggedMessage;
|
||||
|
||||
public alias ResponseHandler = void function(byte[]);
|
||||
|
||||
public abstract class Request
|
||||
{
|
||||
private byte[] requestMessage;
|
||||
|
||||
// TODO: Define the below with an alias for a function pointer that accepts a byte[] (the response data)
|
||||
|
||||
private ResponseHandler respFunc;
|
||||
|
||||
protected this(byte[] requestMessage, ResponseHandler respFunc)
|
||||
{
|
||||
this.requestMessage = requestMessage;
|
||||
this.respFunc = respFunc;
|
||||
}
|
||||
|
||||
package final byte[] getRequestData()
|
||||
{
|
||||
return requestMessage;
|
||||
}
|
||||
|
||||
package final void process(byte[] responseData)
|
||||
{
|
||||
respFunc(responseData);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue