
Your opinion will help to improve our service
Leave a feedback >#include <userver/engine/task/task_base.hpp>
Base class for all the asynchronous tasks (engine::Task, engine::SharedTask, engine::SharedTaskWithResult, engine::TaskWithResult, dist_lock::DistLockedTask, ...).
Definition at line 33 of file task_base.hpp.
Inheritance diagram for engine::TaskBase:Public Types | |
| 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... | |
Public Member Functions | |
| 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. | |
| bool | WaitNothrow () const noexcept |
| Suspends execution until the task finishes or caller is cancelled. Can be called from coroutine context only. For non-coroutine context use BlockingWait(). | |
| FutureStatus | WaitNothrowUntil (Deadline) const noexcept |
| 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 |
Static Public Member Functions | |
| static std::string_view | GetStateName (State state) |
|
strong |
Task importance.
Definition at line 36 of file task_base.hpp.
|
strong |
Task state.
Definition at line 48 of file task_base.hpp.
|
strong |
Task wait mode.
| Enumerator | |
|---|---|
| kSingleWaiter | Can be awaited by at most one task at a time. |
| kMultipleWaiters | Can be awaited by multiple tasks simultaneously. |
Definition at line 59 of file task_base.hpp.
| void engine::TaskBase::BlockingWait | ( | ) | const |
Waits for the task in non-coroutine context (e.g. non-TaskProcessor's std::thread).
| bool engine::TaskBase::IsValid | ( | ) | const |
Checks whether this object owns an actual task (not State::kInvalid)
An invalid task cannot be used. The task becomes invalid after each of the following calls:
Detach()Get() (see engine::TaskWithResult) | void engine::TaskBase::Wait | ( | ) | const |
Suspends execution until the task finishes or caller is cancelled. Can be called from coroutine context only. For non-coroutine context use BlockingWait().
| WaitInterruptedException | when current_task::IsCancelRequested() and no TaskCancellationBlockers are present. |
| void engine::TaskBase::WaitFor | ( | const std::chrono::duration< Rep, Period > & | duration | ) | const |
Suspends execution until the task finishes or after the specified timeout or until caller is cancelled.
| WaitInterruptedException | when current_task::IsCancelRequested() and no TaskCancellationBlockers are present. |
Definition at line 180 of file task_base.hpp.
|
nodiscardnoexcept |
Suspends execution until the task finishes or caller is cancelled. Can be called from coroutine context only. For non-coroutine context use BlockingWait().
false when current_task::IsCancelRequested() and no TaskCancellationBlockers are present.
|
nodiscardnoexcept |
Suspends execution until the task finishes or until the specified deadline is reached or until caller is cancelled.
current_task::IsCancelRequested() and no TaskCancellationBlockers are present. | void engine::TaskBase::WaitUntil | ( | const std::chrono::time_point< Clock, Duration > & | until | ) | const |
Suspends execution until the task finishes or until the specified time point is reached or until caller is cancelled.
| WaitInterruptedException | when current_task::IsCancelRequested() and no TaskCancellationBlockers are present. |
Definition at line 185 of file task_base.hpp.
| void engine::TaskBase::WaitUntil | ( | Deadline | ) | const |
Suspends execution until the task finishes or until the specified deadline is reached or until caller is cancelled.
| WaitInterruptedException | when current_task::IsCancelRequested() and no TaskCancellationBlockers are present. |
|
friend |
Definition at line 173 of file task_base.hpp.