olp-cpp-sdk  1.18.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
olp::client::TaskContext Class Reference

Encapsulates the execution of an asynchronous task and invocation of a callback in a guaranteed manner. More...

#include <TaskContext.h>

Classes

class  Impl
 An implementation helper interface used to declare the Execute, BlockingCancel, and CancelToken functions used by the TaskContext instance. More...
 
class  TaskContextImpl
 Implements the Impl interface. More...
 

Public Member Functions

void Execute () const
 Checks for the cancellation, executes the task, and calls the callback with the result or error.
 
bool BlockingCancel (std::chrono::milliseconds timeout=std::chrono::seconds(60)) const
 Cancels the operation and waits for the notification. More...
 
client::CancellationToken CancelToken () const
 Provides a token to cancel the task. More...
 
bool operator== (const TaskContext &other) const
 Checks whether the values of the TaskContext parameter are the same as the values of the other parameter. More...
 

Static Public Member Functions

template<typename Exec , typename Callback >
static TaskContext Create (Exec execute_func, Callback callback, client::CancellationContext context=client::CancellationContext())
 Creates the TaskContext instance with the provided task and callback. More...
 

Protected Member Functions

template<typename Exec , typename Callback , typename ExecResult = typename std::result_of< Exec(client::CancellationContext)>::type>
void SetExecutors (Exec execute_func, Callback callback, client::CancellationContext context)
 Sets the executors for the request. More...
 

Protected Attributes

std::shared_ptr< Implimpl_
 The Impl instance.
 

Friends

struct TaskContextHash
 A helper for unordered containers.
 

Detailed Description

Encapsulates the execution of an asynchronous task and invocation of a callback in a guaranteed manner.

When the result of the provided task is available, or an error occurs, the callback is invoked.

Member Function Documentation

◆ BlockingCancel()

bool olp::client::TaskContext::BlockingCancel ( std::chrono::milliseconds  timeout = std::chrono::seconds(60)) const
inline

Cancels the operation and waits for the notification.

Parameters
timeoutThe time (in milliseconds) to wait for the task to finish.
Returns
True if the notification is returned before the timeout; false otherwise.

◆ CancelToken()

client::CancellationToken olp::client::TaskContext::CancelToken ( ) const
inline

Provides a token to cancel the task.

Returns
The CancellationToken instance.

◆ Create()

template<typename Exec , typename Callback >
static TaskContext olp::client::TaskContext::Create ( Exec  execute_func,
Callback  callback,
client::CancellationContext  context = client::CancellationContext() 
)
inlinestatic

Creates the TaskContext instance with the provided task and callback.

Parameters
execute_funcThe task that should be executed.
callbackIs invoked once the result of execute_func is available or the task is cancelled.
contextThe CancellationContext instance.
Returns
The TaskContext instance that can be used to run or cancel the task.

◆ operator==()

bool olp::client::TaskContext::operator== ( const TaskContext other) const
inline

Checks whether the values of the TaskContext parameter are the same as the values of the other parameter.

Parameters
otherThe TaskContext instance.
Returns
True if the values of the TaskContext and other parameters are equal; false otherwise.

◆ SetExecutors()

template<typename Exec , typename Callback , typename ExecResult = typename std::result_of< Exec(client::CancellationContext)>::type>
void olp::client::TaskContext::SetExecutors ( Exec  execute_func,
Callback  callback,
client::CancellationContext  context 
)
inlineprotected

Sets the executors for the request.

Parameters
execute_funcThe task that should be executed.
callbackIs invoked once the result of execute_func is available or the task is cancelled.
contextThe CancellationContext instance.

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