#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 154 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 () |
| TaskBuilderNoTracing | NoTracing () |
| 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 218 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 262 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 275 of file task_builder.hpp.
|
inline |
Set "critical" flag for the new task.
Definition at line 194 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 210 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 177 of file task_builder.hpp.
|
inlinenodiscard |
The following call to Build will spawn a task without any tracing::Span.
Definition at line 186 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 167 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 202 of file task_builder.hpp.
|
friend |
Ensures that TaskBuilder{} produces a TaskBuilderBase.
Definition at line 245 of file task_builder.hpp.