scopedTask
fn
auto scopedTask(alias fun, Args...)(Args args)These functions allow the creation of Task objects on the stack rather than the GC heap. The lifetime of a Task created by scopedTask cannot exceed the lifetime of the scope it was created in.
scopedTask might be preferred over task:
- When a
Taskthat calls a delegate is being created and a closure
cannot be allocated due to objects on the stack that have scoped destruction. The delegate overload of scopedTask takes a scope delegate.
- As a micro-optimization, to avoid the heap allocation associated with
task or with the creation of a closure.
Usage is otherwise identical to task.
Notes: Task objects created using scopedTask will automatically call Task.yieldForce in their destructor if necessary to ensure the Task is complete before the stack frame they reside on is destroyed.
fn
auto scopedTask(F, Args...)(scope F delegateOrFp, Args args) if (is(typeof(delegateOrFp(args))) && !isSafeTask!F)Ditto
fn
@trusted auto scopedTask(F, Args...)(F fun, Args args) if (__traits(compiles, () @safe => fun(args)) && isSafeTask!F)Ditto