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);
Task extension to be used with the TaskWith class.