Executor framework with future-based task submission and pluggable thread execution engines
You can add this to your project easily by using:
dub add guillotine
The full API is documented at here.
Tests the submission of three tasks using the Sequential
provider and with the first two tasks having values to return and the last having nothing.
import guillotine.providers.sequential;
import guillotine.executor;
import guillotine.future;
import guillotine.result;
import guillotine.provider;
Provider provider = new Sequential();
// Start the provider so it can execute
// submitted tasks
provider.start();
// Create an executor with this provider
Executor t = new Executor(provider);
// Submit a few tasks
Future fut1 = t.submitTask!(hi);
Future fut2 = t.submitTask!(hiFloat);
Future fut3 = t.submitTask!(hiVoid);
// Await on the first task
writeln("Fut1 waiting...");
Result res1 = fut1.await();
writeln("Fut1 done with: '", res1.getValue().value.integer, "'");
// Stops the internal task runner thread
provider.stop();
Let's also define those functions we are using:
public int hi()
{
writeln("Let's go hi()!");
// Pretend to do some work
Thread.sleep(dur!("seconds")(2));
return 69;
}
public float hiFloat()
{
writeln("Let's go hiFloat()!");
// Pretend to do some work
Thread.sleep(dur!("seconds")(10));
return 69.420;
}
public void hiVoid()
{
writeln("Let's go hiVoid()!");
// Pretend to do some work
Thread.sleep(dur!("seconds")(10));
}