Skip to content

Commit

Permalink
Fix compile error when calling async() an unshared delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Mar 11, 2016
1 parent 0b4f51e commit a8faddf
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion source/vibe/core/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,8 @@ Future!(ReturnType!CALLABLE) async(CALLABLE, ARGS...)(CALLABLE callable, ARGS ar
if (is(typeof(callable(args)) == ReturnType!CALLABLE))
{
import vibe.core.core;
import std.functional : toDelegate;

alias RET = ReturnType!CALLABLE;
Future!RET ret;
ret.init();
Expand All @@ -1137,7 +1139,7 @@ Future!(ReturnType!CALLABLE) async(CALLABLE, ARGS...)(CALLABLE callable, ARGS ar
static if (isWeaklyIsolated!CALLABLE && isWeaklyIsolated!ARGS) {
ret.m_task = runWorkerTaskH(&compute, ret.m_result, callable, args);
} else {
ret.m_task = runTask(&compute, ret.m_result, callable, args);
ret.m_task = runTask(toDelegate(&compute), ret.m_result, callable, args);
}
return ret;
}
Expand All @@ -1163,6 +1165,29 @@ unittest {
}
}

///
unittest {
int sum(int a, int b)
{
return a + b;
}

static int sum2(int a, int b)
{
return a + b;
}

void test()
{
// Using a delegate will use runTask internally
assert(async(&sum, 2, 3).getResult() == 5);

// Using a static function will use runTaskWorker internally,
// if all arguments are weakly isolated
assert(async(&sum2, 2, 3).getResult() == 5);
}
}

/******************************************************************************/
/******************************************************************************/
/* std.concurrency compatible interface for message passing */
Expand Down

0 comments on commit a8faddf

Please sign in to comment.