Skip to content

Commit

Permalink
Merge pull request #403 from vibe-d/issue_138_immutable_task_arguments
Browse files Browse the repository at this point in the history
Allow immutable arguments to be passed to task callbacks. Fixes #138.
  • Loading branch information
l-kramer authored Jul 27, 2024
2 parents dc0fb0d + 9c03d57 commit fac01af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/vibe/core/task.d
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ package struct TaskFuncInfo {
typedCallable!CALLABLE = callable;
foreach (i, A; ARGS) {
static if (needsMove!A) args[i].move(typedArgs!TARGS.expand[i]);
else static if (is(A == immutable)) *cast(Unqual!A*)&typedArgs!TARGS.expand[i] = *cast(Unqual!A*)&args[i];
else typedArgs!TARGS.expand[i] = args[i];
}
} ();
Expand Down
10 changes: 10 additions & 0 deletions source/vibe/core/taskpool.d
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,13 @@ nothrow @safe:
return true;
}
}


unittest { // #138 - immutable arguments
auto tp = new shared TaskPool;
struct S { int[] x; }
auto s = immutable(S)([1, 2]);
tp.runTaskH((immutable S s) { assert(s.x == [1, 2]); }, s)
.joinUninterruptible();
tp.terminate();
}

0 comments on commit fac01af

Please sign in to comment.