olp-cpp-sdk
1.21.0
|
A wrapper that manages the cancellation state of an asynchronous operation in a thread-safe way. More...
#include <CancellationContext.h>
Public Types | |
using | ExecuteFuncType = std::function< CancellationToken()> |
An alias for the operation function. | |
using | CancelFuncType = std::function< void()> |
An alias for the cancellation function. | |
Public Member Functions | |
bool | ExecuteOrCancelled (const ExecuteFuncType &execute_fn, const CancelFuncType &cancel_fn=nullptr) |
Executes the given cancellable code block if the operation is not cancelled. More... | |
void | CancelOperation () |
Cancels the ongoing operation in a thread-safe way. | |
bool | IsCancelled () const |
Checks whether this context is cancelled. More... | |
Friends | |
struct | CancellationContextHash |
A helper for unordered containers. | |
A wrapper that manages the cancellation state of an asynchronous operation in a thread-safe way.
All public APIs are thread-safe.
This class is both movable and copyable.
|
inline |
Executes the given cancellable code block if the operation is not cancelled.
Otherwise, executes the custom cancellation function.
execute_fn | The function that should be executed if this operation is not cancelled. This function should return CancellationToken for which CancellationContext propagates a cancel request. |
cancel_fn | The function that is called if this operation is cancelled. |
|
inline |
Checks whether this context is cancelled.