The OpenD Programming Language

scopedTask

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:

1. When a Task that 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.

2. 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.

  1. auto scopedTask(Args args)
    scopedTask
    (
    alias fun
    Args...
    )
    (
    Args args
    )
  2. auto scopedTask(F delegateOrFp, Args args)
  3. auto scopedTask(F fun, Args args)

Meta