olp-cpp-sdk
1.21.0
|
Implements the Impl
interface.
More...
#include <TaskContext.h>
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< State > | state_ |
The State enum of the atomic type. | |
Implements the Impl
interface.
Erases the type of the Result
object produced by the ExecuteFunc
function and passes it to the UserCallback
instance.
T | The result type. |
|
strong |
|
inline |
Creates the TaskContextImpl
instance.
execute_func | The task that should be executed. |
callback | Is invoked once the result of execute_func is available or the task is cancelled. |
context | The CancellationContext instance. |
|
inlineoverridevirtual |
Cancels the operation and waits for the notification.
timeout | The time (in milliseconds) to wait for the task to finish. |
Implements olp::client::TaskContext::Impl.
|
inlineoverridevirtual |
Provides a token to cancel the task.
CancellationToken
instance. Implements olp::client::TaskContext::Impl.
std::mutex olp::client::TaskContext::TaskContextImpl< Response >::mutex_ |
The mutex lock used to protect from the concurrent read and write operations.