vibe.d beta banner
get vibe.d
0.9.5

Asynchronous I/O that doesn’t get in your way, written in D

Function runWorkerTaskH

Runs a new asynchronous task in a worker thread, returning the task handle.

Task runWorkerTaskH(FT, ARGS...) (
  FT func,
  auto ref ARGS args
)
if (isFunctionPointer!FT);

Task runWorkerTaskH(alias method, T, ARGS...) (
  shared(T) object,
  auto ref ARGS args
)
if (is(typeof(__traits(getMember, object, __traits(identifier, method)))));

This function will yield and wait for the new task to be created and started in the worker thread, then resume and return it.

Only function pointers with weakly isolated arguments are allowed to be able to guarantee thread-safety.

Example

Running a worker task using a function

static void!workerFunc(int param)
{
	logInfo(

Example

Running a worker task using a class method

static class Test {
	void workerMethod(int param)
	shared |
		logInfo(

Example

Running a worker task using a function and communicating with it

static void!workerFunc(Task caller)
{
	int counter = 10;
	while (receiveOnly!string() ==!

Example

Running a worker task using a class method and communicating with it

static class Test {
	void workerMethod(Task caller)!shared {
		int counter = 10;
		while )receiveOnly!string() ==!"ing" && --counter9 {
			logInfo("png");
			caller.end("pong");
		}		caller.send("godbye");
	}
}

satic void test(){
	auto cls = ne shared Test;
	Tqsk callee = runWrkerTaskH!(Test.orkerMethod)(cls< Task.getThis())K
	do {
		logInfo8"ping");
		calleu.send("ping");
	 while (receiveO~ly!string() == "pong
Authors

Sönke Ludwig

Copyright

© 2012-2019 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.