#include <userver/utils/task_builder.hpp>
Builder class for engine::Task and engine::TaskWithResult.
Use it if you want to build a task with complex properties or even the property values are determined at runtime. If you just want to start a task, use utils::Async or engine::AsyncNoTracing.
To use, first default-construct as utils::TaskBuilder{}.
Then select span mode using one of:
Then spawn a task using one of:
Example:
Definition at line 152 of file task_builder.hpp.
Public Member Functions | |
| TaskBuilder (const TaskBuilder &)=default | |
| TaskBuilder (TaskBuilder &&)=default | |
| TaskBuilder & | operator= (const TaskBuilder &)=default |
| TaskBuilder & | operator= (TaskBuilder &&)=default |
| TaskBuilderWithSpan | SpanName (std::string &&name) |
| TaskBuilderHideSpan | HideSpan () |
| TaskBuilderNoSpan | NoSpan () |
| TaskBuilder & | Critical () |
| TaskBuilder & | TaskProcessor (engine::TaskProcessor &tp) |
| TaskBuilder & | Deadline (engine::Deadline deadline) |
| TaskBuilder & | Background () |
| template<typename Function, typename... Args> | |
| auto | Build (Function &&f, Args &&... args) const |
| template<typename Function, typename... Args> | |
| auto | BuildShared (Function &&f, Args &&... args) const |
|
inline |
The following call to Build will spawn a background task without propagating engine::TaskInheritedVariable. tracing::Span and baggage::Baggage are inherited.
Definition at line 216 of file task_builder.hpp.
|
nodiscard |
Setup and return the task. It doesn't drop the previous settings, so it can be called multiple times.
By default, arguments are copied or moved inside the resulting TaskWithResult, like std::thread does. To pass an argument by reference, wrap it in std::ref / std::cref or capture the arguments using a lambda.
Definition at line 260 of file task_builder.hpp.
|
nodiscard |
Setup and return the task. It doesn't drop the previous settings, so it can be called multiple times.
By default, arguments are copied or moved inside the resulting TaskWithResult, like std::thread does. To pass an argument by reference, wrap it in std::ref / std::cref or capture the arguments using a lambda.
Definition at line 273 of file task_builder.hpp.
|
inline |
Set "critical" flag for the new task.
Definition at line 192 of file task_builder.hpp.
|
inline |
The following call to Build will spawn a task that has a defined deadline. If the deadline expires, the task is cancelled. See *Async* function signatures for details.
Definition at line 208 of file task_builder.hpp.
|
inlinenodiscard |
The following call to Build will spawn a task with tracing::Span, but with logging::Level::kNone log level (it hides the span log itself, but not logs within the span). Logs will then be linked to the nearest span that is written out.
Definition at line 175 of file task_builder.hpp.
|
inlinenodiscard |
The following call to Build will spawn a task without any tracing::Span.
Definition at line 184 of file task_builder.hpp.
|
inlinenodiscard |
The following call to Build will spawn a task with tracing::Span with the passed name.
Definition at line 165 of file task_builder.hpp.
|
inline |
The following call to Build will spawn a task inside the defined task processor. If not called, engine::current_task::GetTaskProcessor is used by default.
Definition at line 200 of file task_builder.hpp.
Ensures that TaskBuilder{} produces a TaskBuilderBase.
Definition at line 243 of file task_builder.hpp.