TaskWith

Task descendant which supports extensions that alter the semantics of suspending and resuming the task. An arbitrary number of extensions may be specified (see Params).

Each extension must be a struct which defines one or more of the following methods: - void onBeforeSuspend ( ) - void onBeforeResume ( ) - void onResumed ( ) // called right after execution gets back to task

There is no onSuspended hook because it would be executed in the context of the caller fiber, right after the current task yields. Such a context tends to be neither well-defined nor useful in practice.

The relevant extension methods are called before this.suspend / this.resume in the same order as they are supplied via the template argument list.

The relevant extension methods are called after this.suspend / this.resume in the reverse order that they are supplied via the template argument list.

Constructors

this
this()

Constructor

Members

Functions

assignTo
void assignTo(WorkerFiber fiber, void delegate() entry_point)

Ensures extensions are reset to initial state when task is assigned to new worker fiber.

resume
void resume()

Resumes this task, calls extension methods before resuming (if there are any).

suspend
void suspend()

Suspends this task, calls extension methods before and after suspending (if there are any).

Inherited Members

From Task

object_pool_index
size_t object_pool_index;

Reserved index field which ensures that any Task derivative can be used with ObjectPool. That comes at minor cost of one unused size_t per Task instance if not needed which is not a problem.

fiber
WorkerFiber fiber;

Fiber this task executes in

getThis
Task getThis()
assignTo
void assignTo(WorkerFiber fiber, void delegate() entry_point)

Assigns the task to a fiber. In most cases you need to use Scheduler.schedule instead.

suspend
void suspend()

Suspends execution of this task.

resume
void resume()

Resumes execution of this task. If task has not been started yet, starts it.

terminationHook
void terminationHook(void delegate() hook)

Registers a termination hook that will be executed when the Task is killed.

removeTerminationHook
void removeTerminationHook(void delegate() hook)

Unregisters a termination hook that would be executed when the Task is killed.

suspended
bool suspended()
finished
bool finished()
kill
void kill(istring file, int line)

Forces abnormal termination for the task by throwing special exception instance.

recycle
void recycle()

Method that will be run by scheduler when task finishes. Must be overridden by specific task class to reset reusable resources.

run
void run()

Method that must be overridden in actual application/library task classes to provide entry point.

entryPoint
bool entryPoint()

Internal wrapper around this.run() which is used as primary fiber entry point and ensures any uncaught exception propagates to the context that has started this task.

Parameters

Extensions

variadic template argument list of extensions to use

Examples

// see tests/examples in ocean.task.extensions.*

Meta