Fully implemented dispatcher

This commit is contained in:
Tristan B. Velloza Kildaire 2021-09-09 23:00:33 +02:00
parent 72082d8d23
commit f9b2d24e8c
1 changed files with 18 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import core.sync.mutex : Mutex;
import tristanable.manager;
import std.socket : Socket;
import tristanable.queue : Queue;
import tristanable.queueitem;
import tristanable.encoding : DataMessage, encodeForSend;
import eventy;
@ -57,8 +58,11 @@ public final class TaskManager : Thread
/* If the job is fulfilled */
if(job.isFulfilled())
{
/* Get the job's task */
Task jobTask = job.getTask();
/* Get the Event for dispatching */
Event dispatchEvent = job.getEventForDispatch();
/* Dispatch the event */
eventEngine.push(dispatchEvent);
/* Free the tristanable tag for this job */
job.complete();
@ -116,6 +120,18 @@ public final class TaskManager : Thread
return tEncoded;
}
public Event getEventForDispatch()
{
/* Dequeue the data from the tristanable queue */
QueueItem queueItem = tristanableTag.dequeue();
byte[] receivedData = queueItem.getData();
/* Parse into Event (based on the Job's task type) and return */
Event eventToDispatch = task.getEvent(receivedData);
return eventToDispatch;
}
public bool isFulfilled()
{
return tristanableTag.poll();