Scheduler.await

Schedules the argument and suspends calling task until the argument finishes.

This method must not be called outside of a task.

If task is already scheduled, it will not be re-scheduled again but awaiting will still occur.

class Scheduler
void
await
(,
scope void delegate finished_dg = null
)

Parameters

task Task

task to schedule and wait for

finished_dg void delegate

optional delegate called after task finishes but before it gets recycled, can be used to copy some data into caller fiber context

Examples

void example ( )
{
    static class ExampleTask : Task
    {
        mstring data;

        override void run ( )
        {
            // do things that may result in suspending ...
            data = "abcd".dup;
        }

        override void recycle ( )
        {
            this.data = null;
        }
    }

    mstring data;

    theScheduler.await(
        new ExampleTask,
        (Task t) {
            // copy required data before tasks gets recycled
            auto task = cast(ExampleTask) t;
            data = task.data.dup;
        }
    );

    test!("==")(data, "abcd");
}

Meta