Compare commits

...

10 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 73bec426e0 Task
- Fixed missing `eventy.result` import to resolve the `Result` type
2023-03-03 17:32:39 +02:00
Tristan B. Velloza Kildaire d2cc6a8e93 Testing
- Added a playground where I test stuff
2023-03-03 17:31:46 +02:00
Tristan B. Velloza Kildaire 30178efb9c Package
- Added a package
2023-03-03 17:31:29 +02:00
Tristan B. Velloza Kildaire 79ba136e87 Result
- Added `Result` which is what a `Promise` returns when done executing
2023-03-03 17:31:14 +02:00
Tristan B. Velloza Kildaire 7d17b82c03 Engine
- Added an `Engine` which manages all promises and their tasks
2023-03-03 17:30:51 +02:00
Tristan B. Velloza Kildaire 9271fabfa9 Task
- Added a Task which represents the work done by a Promise
2023-03-03 17:30:33 +02:00
Tristan B. Velloza Kildaire 2f57083760 - Added code 2023-03-03 17:17:58 +02:00
Tristan B. Velloza Kildaire 7121f02321 Promise
- Added module `promise`
2023-03-03 17:17:53 +02:00
Tristan B. Velloza Kildaire abe198f6d2 - Update .gitignore 2023-03-03 17:17:07 +02:00
Tristan B. Velloza Kildaire 32aa98d125 Dub
- Added `libsnooze` as a dependency
2023-03-03 17:16:58 +02:00
8 changed files with 177 additions and 0 deletions

1
.gitignore vendored
View File

@ -16,3 +16,4 @@ eventdisp-test-*
libeventdisp.a
eventy-test-library
libeventy.a
dub.selections.json

View File

@ -3,6 +3,9 @@
"Tristan B. Velloza Kildaire"
],
"copyright": "Copyright © 2020, Tristan B. Velloza Kildaire",
"dependencies": {
"libsnooze": "~>0.2.9"
},
"description": "Asynchronous programming system",
"homepage": "http://deavmi.assigned.network/projects/eventy",
"license": "LGPL v3",

30
source/eventy/engine.d Normal file
View File

@ -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;
}
}

2
source/eventy/package.d Normal file
View File

@ -0,0 +1,2 @@
module eventy;

70
source/eventy/promise.d Normal file
View File

@ -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)
{
}
}

12
source/eventy/result.d Normal file
View File

@ -0,0 +1,12 @@
module eventy.result;
/**
* Result
*
* A result is the, well, result of a task
* (upon its completion)
*/
public class Result
{
}

49
source/eventy/task.d Normal file
View File

@ -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;
}
}

10
source/eventy/test.d Normal file
View File

@ -0,0 +1,10 @@
module eventy.test;
import std.stdio;
unittest
{
writeln((()=>(2)) ());
}