Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add delegate support for task submission #2

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions source/guillotine/executor.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import guillotine.future : Future;
import guillotine.value;
import guillotine.result : Result;
import guillotine.provider;
import std.traits : isFunction, FunctionTypeOf, ReturnType, arity;
import std.traits : isFunction, isDelegate, FunctionTypeOf, ReturnType, arity;
import std.functional : toDelegate;

// TODO: Document
private bool isSupportedReturn(alias FuncSymbol)()
Expand Down Expand Up @@ -44,7 +45,7 @@ private class FutureTask : Task
/**
* Function to call
*/
private Value function() func;
private Value delegate() func;

/**
* Constructs a new `FutureTask` with the
Expand All @@ -54,7 +55,7 @@ private class FutureTask : Task
* future = the `Future` to associate with
* func = the function to run
*/
this(Future future, Value function() func)
this(Future future, Value delegate() func)
{
this.future = future;
this.func = func;
Expand Down Expand Up @@ -217,15 +218,21 @@ public class Executor
* Returns: the task's `Future`
*/
public Future submitTask(alias Symbol)()
if (isFunction!(Symbol) && isSupportedFunction!(Symbol))
if ((isFunction!(Symbol) || isDelegate!(Symbol)) && isSupportedFunction!(Symbol))
{
FutureTask task;

Value function() ptr;
Value delegate() ptr;
alias func = Symbol;


ptr = &WorkerFunction!(func).workerFunc;
static if(isDelegate!(Symbol))
{
ptr = &WorkerFunction!(func).workerFunc;
}
else
{
ptr = toDelegate(&WorkerFunction!(func).workerFunc);
}

version(unittest)
{
Expand Down