Constructor. Used only to insert debug trace message.
Assigns the task to a fiber. In most cases you need to use Scheduler.schedule instead.
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.
Forces abnormal termination for the task by throwing special exception instance.
Method that will be run by scheduler when task finishes. Must be overridden by specific task class to reset reusable resources.
Unregisters a termination hook that would be executed when the Task is killed.
Resumes execution of this task. If task has not been started yet, starts it.
Method that must be overridden in actual application/library task classes to provide entry point.
Suspends execution of this task.
Registers a termination hook that will be executed when the Task is killed.
Fiber this task executes in
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.
// represents some limited resource used by this task (e.g. memory or a // file handle) class LimitedResourceHandle { } LimitedResourceHandle getResource ( ) { return null; } void releaseResource ( LimitedResourceHandle ) { } // example custom task class class MyTask : Task { LimitedResourceHandle resource; override public void run ( ) { this.resource = getResource(); } override public void recycle ( ) { releaseResource(this.resource); } } // Example of running a task by manually spawning a worker fiber. // More commonly, it is instead done via ocean.task.Scheduler. auto task = new MyTask; // a large stack size is important for debug traces to not crash tests: task.assignTo(new WorkerFiber(10240)); task.resume();
Minimal usable Task class.
Serves as a base for all other task classes. Provides the following functionality: * assigning a task to an arbitrary fiber (assignTo()) * wraps the abstract run() method in a try/catch statement which rethrows any unhandled exceptions