You.i Engine
CYICallableTask< ResultType, Callable, Args > Class Template Reference

Detailed Description

template<typename ResultType = void, typename Callable = void, typename... Args>
class CYICallableTask< ResultType, Callable, Args >

An utility class used to create a task from a callable object.

Callable objects can be any object that can be called as a function. This include std::function objects, static functions, lambdas as well as any object that implements operator().

Parameters to be passed to the callable object are supported in this class. A copy of the parameter values is stored within the CYICallableTask object. Move-only types are supported as parameters.

Note
It is preferable to use the YiMakeTask helper functions to create CYICallableTask objects.
Warning
Passing raw pointers to tasks is not recommended as ownership of the raw pointer and lifetime of the pointed-to memory is difficult to manage.

Sample usage:

auto pTask = YiMakeTask(myFutureObject, [](int intValue, CYIString stringValue) {
return stringValue + intValue;
}, 42, CYIString("foo"));
Template Parameters
ResultTypethe return type of the callable object.
Callablethe type of the callable object
Argsthe (optional) arguments for calling the callable object with
See also
YiMakeTask()

#include <thread/YiCallableTask.h>

Inheritance diagram for CYICallableTask< ResultType, Callable, Args >:

Public Member Functions

 CYICallableTask (Callable callable, Args &&... args)
 
 CYICallableTask (CYIFuture< ResultType > future, Callable callable, Args &&... args)
 
virtual ResultType Run () override
 
- Public Member Functions inherited from CYITask< ResultType >
 CYITask ()
 
 CYITask (CYIFuture< ResultType > future)
 
bool SetFuture (CYIFuture< ResultType > future)
 
- Public Member Functions inherited from CYITaskBase
virtual ~CYITaskBase ()
 
State GetState () const
 
bool MarkPendingExecution ()
 
void RequestCancellation ()
 
bool IsCancellationRequested () const
 
void SetCancellationRequestSucceeded ()
 
bool IsCancellationRequestSucceeded () const
 
bool Execute ()
 

Additional Inherited Members

- Public Types inherited from CYITaskBase
enum  State : uint8_t {
  State::New,
  State::PendingExecution,
  State::Executing,
  State::Completed,
  State::Cancelled
}
 

Constructor & Destructor Documentation

◆ CYICallableTask() [1/2]

template<typename ResultType = void, typename Callable = void, typename... Args>
CYICallableTask< ResultType, Callable, Args >::CYICallableTask ( Callable  callable,
Args &&...  args 
)

Creates a task from the callable object callable, with optional arguments args. No future is initially associated with the task.

Note
If the first parameter of the Callable is a CYITaskBase*, the task itself will be passed as a parameter to callable when the task is executed. This allows the Callable to detect and respond to cancellation requests.
See also
YiMakeTask(Callable, Args&&..)

◆ CYICallableTask() [2/2]

template<typename ResultType = void, typename Callable = void, typename... Args>
CYICallableTask< ResultType, Callable, Args >::CYICallableTask ( CYIFuture< ResultType >  future,
Callable  callable,
Args &&...  args 
)

Creates a task from the callable object callable, with optional arguments args. The future future is associated with the task.

Note
If the first parameter of the Callable is a CYITaskBase*, the task itself will be passed as a parameter to callable when the task is executed. This allows the Callable to detect and respond to cancellation requests.
See also
YiMakeTask(CYIFuture<ResultType> &, Callable, Args&&..)

Member Function Documentation

◆ Run()

template<typename ResultType = void, typename Callable = void, typename... Args>
virtual ResultType CYICallableTask< ResultType, Callable, Args >::Run ( )
overridevirtual

The function executed by this task. Implement this function in a sub-classe to implement your own task.

Returns
Returns the result of the task's execution.

Implements CYITask< ResultType >.


The documentation for this class was generated from the following file: