On Wed, 26 Mar 2014 15:40:57 GMT, Luca Niccoli wrote:

A general function could be maybe written as

Task getWorkerTask(R, ARGS...)(R function(ARGS) func, ARGS args)
{
	foreach (T; ARGS) static assert(isWeaklyIsolated!T, "Argument type "~T.stringof~" is not safe to pass between threads.");
	Task caller = Task.getThis();
	runWorkerTask_unsafe({
		caller.prioritySend(Task.getThis());
		func(args);
	});
	Task callee;
	receive((Task val) { callee = val; });
	return callee;
}

with a symmetric function for method tasks.

I took a look and

void runWorkerTask(alias method, T, ARGS...)(shared(T) object, ARGS args)

doesn't seem to work: if vibe.d is compiled with MultiThreadTest, for instance, compilation fails at libevent2_tcp.d(529), which uses runWorkerTask:

runWorkerTask(&task.execute);

That line seems wrong on its own, though, as I think it is passing a delegate, not a member function and an object.
I tried

class Class
{
	void execute() shared
	{
		writeln("Executed");
	}
}
shared Class instance = new shared Class();
runWorkerTask!(Class.execute)(instance);

but it fails with

../../vibe.d/source/vibe/core/core.d(224): Error: no property 'method' for type 'shared(Class)'
source/app.d(15): Error: template instance vibe.core.core.runWorkerTask!(execute, Class, ) error instantiating

I'm not sure if this is not supposed to work or it's a bug in DMD...