#include <userver/engine/task/shared_task_with_result.hpp>
Asynchronous task with result that has a shared ownership of payload.
Definition at line 35 of file shared_task_with_result.hpp.
Public Member Functions | |
SharedTaskWithResult ()=default | |
Default constructor. | |
~SharedTaskWithResult ()=default | |
If the task is still valid and is not finished and this is the last shared owner of the payload, cancels the task and waits until it finishes. | |
SharedTaskWithResult (const SharedTaskWithResult &other)=default | |
Assigns the other task into this. | |
SharedTaskWithResult & | operator= (const SharedTaskWithResult &other)=default |
If this task is still valid and is not finished and other task is not the same task as this and this is the last shared owner of the payload, cancels the task and waits until it finishes before assigning the other. Otherwise just assigns the other task into this. | |
SharedTaskWithResult (SharedTaskWithResult &&other) noexcept=default | |
Moves the other task into this, leaving the other in an invalid state. | |
SharedTaskWithResult & | operator= (SharedTaskWithResult &&other) noexcept=default |
If this task is still valid and is not finished and other task is not the same task as this and this is the last shared owner of the payload, cancels the task and waits until it finishes before move assigning the other. Otherwise just move assigns the other task into this, leaving the other in an invalid state. | |
decltype(auto) | Get () const &noexcept(false) |
Returns (or rethrows) the result of task invocation. Task remains valid after return from this method, thread(coro)-safe. | |
std::add_lvalue_reference< const T > | Get () && |
Public Member Functions inherited from engine::SharedTask | |
SharedTask () | |
Default constructor. | |
~SharedTask () | |
If the task is still valid and is not finished and this is the last shared owner of the payload, cancels the task and waits until it finishes. | |
SharedTask (const SharedTask &other) noexcept | |
Assigns the other task into this. | |
SharedTask & | operator= (const SharedTask &other) noexcept |
If this task is still valid and is not finished and other task is not the same task as this and this is the last shared owner of the payload, cancels the task and waits until it finishes before assigning the other. Otherwise just assigns the other task into this. | |
SharedTask (SharedTask &&other) noexcept | |
Moves the other task into this, leaving the other in an invalid state. | |
SharedTask & | operator= (SharedTask &&other) noexcept |
If this task is still valid and is not finished and other task is not the same task as this and this is the last shared owner of the payload, cancels the task and waits until it finishes before move assigning the other. Otherwise just move assigns the other task into this, leaving the other in an invalid state. | |
Public Member Functions inherited from engine::TaskBase | |
bool | IsValid () const |
Checks whether this object owns an actual task (not State::kInvalid ) | |
State | GetState () const |
Gets the task State. | |
bool | IsFinished () const |
Returns whether the task finished execution. | |
void | Wait () const noexcept(false) |
Suspends execution until the task finishes or caller is cancelled. Can be called from coroutine context only. For non-coroutine context use BlockingWait(). | |
template<typename Rep , typename Period > | |
void | WaitFor (const std::chrono::duration< Rep, Period > &) const noexcept(false) |
Suspends execution until the task finishes or after the specified timeout or until caller is cancelled. | |
template<typename Clock , typename Duration > | |
void | WaitUntil (const std::chrono::time_point< Clock, Duration > &) const noexcept(false) |
Suspends execution until the task finishes or until the specified time point is reached or until caller is cancelled. | |
void | WaitUntil (Deadline) const |
Suspends execution until the task finishes or until the specified deadline is reached or until caller is cancelled. | |
void | RequestCancel () |
Queues task cancellation request. | |
void | SyncCancel () noexcept |
Cancels the task and suspends execution until it is finished. Can be called from coroutine context only. For non-coroutine context use RequestCancel() + BlockingWait(). | |
TaskCancellationReason | CancellationReason () const |
Gets task cancellation reason. | |
void | BlockingWait () const |
Additional Inherited Members | |
Public Types inherited from engine::TaskBase | |
enum class | Importance { kNormal , kCritical } |
Task importance. More... | |
enum class | State { kInvalid , kNew , kQueued , kRunning , kSuspended , kCancelled , kCompleted } |
Task state. More... | |
enum class | WaitMode { kSingleWaiter , kMultipleWaiters } |
Task wait mode. More... | |
Static Public Member Functions inherited from engine::TaskBase | |
static const std::string & | GetStateName (State state) |
|
default |
Default constructor.
Creates an invalid task.
|
inline |
Definition at line 87 of file shared_task_with_result.hpp.
|
inline |
Returns (or rethrows) the result of task invocation. Task remains valid after return from this method, thread(coro)-safe.
WaitInterruptedException | when current_task::IsCancelRequested() and no TaskCancellationBlockers are present. |
TaskCancelledException | if no result is available because the task was cancelled |
Definition at line 76 of file shared_task_with_result.hpp.