You.i Engine
CYITaskBase Class Referenceabstract

Detailed Description

Abstract base class for CYITask.

See also
CYITask<ResultType>

#include <thread/YiTask.h>

Inheritance diagram for CYITaskBase:

Public Types

enum  State : uint8_t {
  State::New,
  State::PendingExecution,
  State::Executing,
  State::Completed,
  State::Cancelled
}
 

Public Member Functions

virtual ~CYITaskBase ()
 
State GetState () const
 
bool MarkPendingExecution ()
 
void RequestCancellation ()
 
bool IsCancellationRequested () const
 
void SetCancellationRequestSucceeded ()
 
bool IsCancellationRequestSucceeded () const
 
bool Execute ()
 

Protected Member Functions

virtual void RunAndAssignResult ()=0
 Executes this task and assigns its result to the associated future object, if it exists. More...
 

Friends

class CYIFutureSharedStateBase
 
template<typename T >
class CYITask
 

Member Enumeration Documentation

◆ State

enum CYITaskBase::State : uint8_t
strong

An enum listing the various states that a task can be in.

Enumerator
New 
PendingExecution 
Executing 
Completed 
Cancelled 

Constructor & Destructor Documentation

◆ ~CYITaskBase()

virtual CYITaskBase::~CYITaskBase ( )
virtual

Member Function Documentation

◆ Execute()

bool CYITaskBase::Execute ( )

Executes this task. The task's state will change to State::Completed upon successful execution.

Note
Has no effect if this task is not in the State::New or State::PendingExecution state.
If this task has an associated future object, the ExecutionStarted signal is called and the result of the task's execution is assigned to the future object upon completion (the Completed signal is also triggered).
If execution is terminated prematurely (e.g. through the cancellation of an associated future object), this function may return early and will still report success (e.g. true). In case of premature termination, the task's state will be change to State::Cancelled instead of State::Completed.
Returns
Returns true if the task was successfully executed.

◆ GetState()

State CYITaskBase::GetState ( ) const
Warning
This function should only be used for debugging purposes.
Returns
Returns the state that the task is in.

◆ IsCancellationRequested()

bool CYITaskBase::IsCancellationRequested ( ) const

A function used to check if a cancellation has been requested for an already-executing task. Subclasses of this class can use this function to check if they should abort execution of the task.

Returns
Returns true if a cancellation has been requested for this task.

◆ IsCancellationRequestSucceeded()

bool CYITaskBase::IsCancellationRequestSucceeded ( ) const

A function used to check if a requested cancellation has succeeded.

Returns
Returns true if a cancellation request has succeeded.

◆ MarkPendingExecution()

bool CYITaskBase::MarkPendingExecution ( )

Marks this task as pending execution.

Note
Has no effect if the task is not in the State::New state.
This is typically only called by classes that execute tasks.
Returns
Returns true if the task was successfully marked as pending execution.

◆ RequestCancellation()

void CYITaskBase::RequestCancellation ( )

Requests the cancellation of this task.

Note
This is typically only called by classes that execute tasks.

◆ RunAndAssignResult()

virtual void CYITaskBase::RunAndAssignResult ( )
protectedpure virtual

Executes this task and assigns its result to the associated future object, if it exists.

◆ SetCancellationRequestSucceeded()

void CYITaskBase::SetCancellationRequestSucceeded ( )

This function can be used to signal that the cancellation of an already-executing task was successful. Subclasses of this class can use this function to indicate that the execution of the task was aborted and that the returned value is invalid. After this function has been called and after the call to Run() has completed, the state of the task will change to State::Cancelled intead of State::Completed.

Note
Should only be called from the Run() function of a subclass.

Friends And Related Function Documentation

◆ CYIFutureSharedStateBase

friend class CYIFutureSharedStateBase
friend

◆ CYITask

template<typename T >
friend class CYITask
friend

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