ExceptionForwarding

Task extension to be used with the TaskWith class.

struct ExceptionForwarding {}

Members

Functions

onResumed
void onResumed()
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

to_throw
Exception to_throw;
Undocumented in source.

Examples

class ExceptionExternal : Exception
{
    this ( )
    {
        super("external");
    }
}

class MyTask : TaskWith!(ExceptionForwarding)
{
    bool caught = false;

    override protected void run ( )
    {
        try
        {
            // when the following call to `this.suspend()` exit (== after
            // resuming by a callback or the scheduler), the stored
            // exception (if any) will be thrown
            this.suspend();
        }
        catch (ExceptionExternal e)
        {
            caught = true;
        }
    }
}

// create a task and assign it to a worker fiber
auto task = new MyTask;
task.assignTo(new WorkerFiber(10240));

// will start the task (which then yields immediately)
task.resume();

// makes stored exception instance thrown from within the task when
// resumed
task.extensions.exception_forwarding.to_throw = new ExceptionExternal;
task.resume();
test(task.caught);

Meta