olp-cpp-sdk  1.19.0
Public Types | Public Member Functions | Public Attributes | List of all members
olp::client::TaskContext::TaskContextImpl< Response > Class Template Reference

Implements the Impl interface. More...

#include <TaskContext.h>

Inheritance diagram for olp::client::TaskContext::TaskContextImpl< Response >:
Inheritance graph
[legend]
Collaboration diagram for olp::client::TaskContext::TaskContextImpl< Response >:
Collaboration graph
[legend]

Public Types

enum class  State { PENDING , IN_PROGRESS , COMPLETED }
 Indicates the state of the request. More...
 
using ExecuteFunc = std::function< Response(client::CancellationContext)>
 The task that produces the Response instance.
 
using UserCallback = std::function< void(Response)>
 Consumes the Response instance.
 

Public Member Functions

 TaskContextImpl (ExecuteFunc execute_func, UserCallback callback, client::CancellationContext context)
 Creates the TaskContextImpl instance. More...
 
void Execute () override
 Checks for the cancellation, executes the task, and calls the callback with the result or error.
 
bool BlockingCancel (std::chrono::milliseconds timeout) override
 Cancels the operation and waits for the notification. More...
 
client::CancellationToken CancelToken () override
 Provides a token to cancel the task. More...
 

Public Attributes

std::mutex mutex_
 
ExecuteFunc execute_func_
 The ExecuteFunc instance.
 
UserCallback callback_
 The UserCallback instance.
 
client::CancellationContext context_
 The CancellationContext instance.
 
client::Condition condition_
 The Condition instance.
 
std::atomic< Statestate_
 The State enum of the atomic type.
 

Detailed Description

template<typename Response>
class olp::client::TaskContext::TaskContextImpl< Response >

Implements the Impl interface.

Erases the type of the Result object produced by the ExecuteFunc function and passes it to the UserCallback instance.

Template Parameters
TThe result type.

Member Enumeration Documentation

◆ State

template<typename Response >
enum olp::client::TaskContext::TaskContextImpl::State
strong

Indicates the state of the request.

Enumerator
PENDING 

The request waits to be executed.

IN_PROGRESS 

The request is being executed.

COMPLETED 

The request execution finished.

Constructor & Destructor Documentation

◆ TaskContextImpl()

template<typename Response >
olp::client::TaskContext::TaskContextImpl< Response >::TaskContextImpl ( ExecuteFunc  execute_func,
UserCallback  callback,
client::CancellationContext  context 
)
inline

Creates the TaskContextImpl instance.

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.

Member Function Documentation

◆ BlockingCancel()

template<typename Response >
bool olp::client::TaskContext::TaskContextImpl< Response >::BlockingCancel ( std::chrono::milliseconds  timeout)
inlineoverridevirtual

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.

Implements olp::client::TaskContext::Impl.

◆ CancelToken()

template<typename Response >
client::CancellationToken olp::client::TaskContext::TaskContextImpl< Response >::CancelToken ( )
inlineoverridevirtual

Provides a token to cancel the task.

Returns
The CancellationToken instance.

Implements olp::client::TaskContext::Impl.

Member Data Documentation

◆ mutex_

template<typename Response >
std::mutex olp::client::TaskContext::TaskContextImpl< Response >::mutex_

The mutex lock used to protect from the concurrent read and write operations.


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