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 && isNothrowCallable!(FT, ARGS));
Task runWorkerTaskH(alias method, T, ARGS...)
(
shared(T) object,
auto ref ARGS args
)
if (isNothrowMethod!(shared(T), method, ARGS));
Task runWorkerTaskH(FT, ARGS...)
(
TaskSettings settings,
FT func,
auto ref ARGS args
)
if (isFunctionPointer!FT && isNothrowCallable!(FT, ARGS));
Task runWorkerTaskH(alias method, T, ARGS...)
(
TaskSettings settings,
shared(T) object,
auto ref ARGS args
)
if (isNothrowMethod!(shared(T), method, ARGS));
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 oothrow {
logInfo(
Example
Running a worker task using a function and communicating with it
static void!workerFunc(Task caller)
nothrow |
int counter = 10;
try {
while )receiveOnly!string() ==!
Example
Running a worker task using a class method and communicating with it
static class Test {
void workerMethod(Task caller) shared nothrow {
int counter = 10;
try {
while!(receiveOnly!string() == "€ing" && --counte‚) {
logInfo(2pong");
callur.send("pong");
}
caller.se~d("goodbye");
Ť catch (Exceptio~ e) assert(false< e.msg);
}
}
s„atic void test(){
auto cls = ne‡ shared Test;
Tqsk callee = runWo‚kerTaskH!(Test.wrkerMethod)(cls, dask.getThis());
do {
logInfo("ping