mirror of https://github.com/deavmi/eventy.git
Compare commits
10 Commits
ea60097153
...
73bec426e0
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 73bec426e0 | |
Tristan B. Velloza Kildaire | d2cc6a8e93 | |
Tristan B. Velloza Kildaire | 30178efb9c | |
Tristan B. Velloza Kildaire | 79ba136e87 | |
Tristan B. Velloza Kildaire | 7d17b82c03 | |
Tristan B. Velloza Kildaire | 9271fabfa9 | |
Tristan B. Velloza Kildaire | 2f57083760 | |
Tristan B. Velloza Kildaire | 7121f02321 | |
Tristan B. Velloza Kildaire | abe198f6d2 | |
Tristan B. Velloza Kildaire | 32aa98d125 |
|
@ -16,3 +16,4 @@ eventdisp-test-*
|
||||||
libeventdisp.a
|
libeventdisp.a
|
||||||
eventy-test-library
|
eventy-test-library
|
||||||
libeventy.a
|
libeventy.a
|
||||||
|
dub.selections.json
|
||||||
|
|
3
dub.json
3
dub.json
|
@ -3,6 +3,9 @@
|
||||||
"Tristan B. Velloza Kildaire"
|
"Tristan B. Velloza Kildaire"
|
||||||
],
|
],
|
||||||
"copyright": "Copyright © 2020, Tristan B. Velloza Kildaire",
|
"copyright": "Copyright © 2020, Tristan B. Velloza Kildaire",
|
||||||
|
"dependencies": {
|
||||||
|
"libsnooze": "~>0.2.9"
|
||||||
|
},
|
||||||
"description": "Asynchronous programming system",
|
"description": "Asynchronous programming system",
|
||||||
"homepage": "http://deavmi.assigned.network/projects/eventy",
|
"homepage": "http://deavmi.assigned.network/projects/eventy",
|
||||||
"license": "LGPL v3",
|
"license": "LGPL v3",
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
module eventy.engine;
|
||||||
|
|
||||||
|
import eventy.promise : Promise;
|
||||||
|
import eventy.task : Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Engine
|
||||||
|
*
|
||||||
|
* The core of the event sub-system, this maintains
|
||||||
|
* promises, allows introspection and control over them
|
||||||
|
* and also allows creating them
|
||||||
|
*
|
||||||
|
* NOTE: Do we even need this? Promises can track (themselves)
|
||||||
|
* who is waiting for them
|
||||||
|
*/
|
||||||
|
public class Engine
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public Promise create(Task task)
|
||||||
|
{
|
||||||
|
// Create a promise associated with this engine instance
|
||||||
|
Promise newPromise = new Promise(this, task);
|
||||||
|
|
||||||
|
|
||||||
|
return newPromise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
module eventy;
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
module eventy.promise;
|
||||||
|
|
||||||
|
import eventy.engine : Engine;
|
||||||
|
import eventy.task : Task;
|
||||||
|
import core.thread : Thread, Duration, dur;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state pf the promise
|
||||||
|
*/
|
||||||
|
public enum PromiseState
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The promise has been created but not yet run
|
||||||
|
*/
|
||||||
|
CREATED,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The promise is running
|
||||||
|
*/
|
||||||
|
RUNNING,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The promise has finished running
|
||||||
|
*/
|
||||||
|
FINISHED
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Promise : Thread
|
||||||
|
{
|
||||||
|
/* Our registered engine to report to */
|
||||||
|
private Engine engine;
|
||||||
|
|
||||||
|
private PromiseState state;
|
||||||
|
private Task task;
|
||||||
|
|
||||||
|
this(Engine engine, Task task)
|
||||||
|
{
|
||||||
|
// Register this promise with the provided engine
|
||||||
|
this.engine = engine;
|
||||||
|
|
||||||
|
// Set our task to execute
|
||||||
|
this.task = task;
|
||||||
|
|
||||||
|
// Our state is created
|
||||||
|
this.state = PromiseState.CREATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the provided task in a seperate thread
|
||||||
|
*/
|
||||||
|
private void worker()
|
||||||
|
{
|
||||||
|
// TODO: Task.execute() call here
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void execute()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void await()
|
||||||
|
{
|
||||||
|
await(dur!("seconds")(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void await(Duration timeout)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
module eventy.result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result
|
||||||
|
*
|
||||||
|
* A result is the, well, result of a task
|
||||||
|
* (upon its completion)
|
||||||
|
*/
|
||||||
|
public class Result
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
module eventy.task;
|
||||||
|
|
||||||
|
import eventy.result : Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task
|
||||||
|
*
|
||||||
|
* A task is the unit of execution that a promise is
|
||||||
|
* to carry out.
|
||||||
|
*/
|
||||||
|
public abstract class Task
|
||||||
|
{
|
||||||
|
public abstract Result worker();
|
||||||
|
|
||||||
|
public final Result doTask()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SimpleTask
|
||||||
|
*
|
||||||
|
* A task that returns an empty result
|
||||||
|
*/
|
||||||
|
public final class SimpleTask : Task
|
||||||
|
{
|
||||||
|
// TODO: Put worker field here
|
||||||
|
|
||||||
|
// TODO: Take in a lambda that takes in no arguments and executes something which returns void
|
||||||
|
this(int x)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: worker calls it
|
||||||
|
public override Result worker()
|
||||||
|
{
|
||||||
|
// TODO: Make a result
|
||||||
|
Result result;
|
||||||
|
|
||||||
|
// TODO: Call worker-field here
|
||||||
|
|
||||||
|
// TODO: You must handle errors and set `result` accordingly
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
module eventy.test;
|
||||||
|
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
writeln((()=>(2)) ());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue