Base class for all the asynchronous tasks (engine::Task, engine::SharedTask, engine::SharedTaskWithResult, engine::TaskWithResult, dist_lock::DistLockedTask, ...).
More...
#include <userver/engine/task/task_base.hpp>
|
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 |
|
|
static const std::string & | GetStateName (State state) |
|
◆ Importance
Task importance.
Enumerator |
---|
kNormal | Normal task.
|
kCritical | Critical task. The task will be started regardless of cancellations, e.g. due to user request, deadline or TaskProcessor overload. After the task starts, it may be cancelled. In particular, if it received any cancellation requests before starting, then it will start as cancelled.
|
Definition at line 40 of file task_base.hpp.
◆ State
Task state.
Enumerator |
---|
kInvalid | Unusable.
|
kNew | just created, not registered with task processor
|
kQueued | awaits execution
|
kRunning | executing user code
|
kSuspended | suspended, e.g. waiting for blocking call to complete
|
kCancelled | exited user code because of external request
|
kCompleted | exited user code with return or throw
|
Definition at line 52 of file task_base.hpp.
◆ WaitMode
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 63 of file task_base.hpp.
◆ BlockingWait()
void engine::TaskBase::BlockingWait |
( |
| ) |
const |
Waits for the task in non-coroutine context (e.g. non-TaskProcessor's std::thread).
◆ IsValid()
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:
- the default constructor
Detach()
Get()
(see engine::TaskWithResult
)
◆ Wait()
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().
- Exceptions
-
◆ WaitFor()
template<typename Rep , typename Period >
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.
- Exceptions
-
Definition at line 191 of file task_base.hpp.
◆ WaitUntil() [1/2]
template<typename Clock , typename Duration >
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.
- Exceptions
-
Definition at line 197 of file task_base.hpp.
◆ WaitUntil() [2/2]
void engine::TaskBase::WaitUntil |
( |
Deadline |
| ) |
const |
Suspends execution until the task finishes or until the specified deadline is reached or until caller is cancelled.
- Exceptions
-
◆ TaskCancellationToken
The documentation for this class was generated from the following file: