userver: utils::TaskBuilder< OptionsImpl > Class Template Reference
Loading...
Searching...
No Matches
utils::TaskBuilder< OptionsImpl > Class Template Reference

#include <userver/utils/task_builder.hpp>

Detailed Description

template<typename OptionsImpl>
class utils::TaskBuilder< OptionsImpl >

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:

See also
intro_tasks

Definition at line 152 of file task_builder.hpp.

Public Member Functions

 TaskBuilder (const TaskBuilder &)=default
 
 TaskBuilder (TaskBuilder &&)=default
 
TaskBuilderoperator= (const TaskBuilder &)=default
 
TaskBuilderoperator= (TaskBuilder &&)=default
 
TaskBuilderWithSpan SpanName (std::string &&name)
 
TaskBuilderHideSpan HideSpan ()
 
TaskBuilderNoSpan NoSpan ()
 
TaskBuilderCritical ()
 
TaskBuilderTaskProcessor (engine::TaskProcessor &tp)
 
TaskBuilderDeadline (engine::Deadline deadline)
 
TaskBuilderBackground ()
 
template<typename Function, typename... Args>
auto Build (Function &&f, Args &&... args) const
 
template<typename Function, typename... Args>
auto BuildShared (Function &&f, Args &&... args) const
 

Member Function Documentation

◆ Background()

template<typename OptionsImpl>
TaskBuilder & utils::TaskBuilder< OptionsImpl >::Background ( )
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.

◆ Build()

template<typename OptionsImpl>
template<typename Function, typename... Args>
auto utils::TaskBuilder< OptionsImpl >::Build ( Function && f,
Args &&... args ) const
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.

Returns
engine::TaskWithResult

Definition at line 260 of file task_builder.hpp.

◆ BuildShared()

template<typename OptionsImpl>
template<typename Function, typename... Args>
auto utils::TaskBuilder< OptionsImpl >::BuildShared ( Function && f,
Args &&... args ) const
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.

Returns
engine::SharedTaskWithResult

Definition at line 273 of file task_builder.hpp.

◆ Critical()

template<typename OptionsImpl>
TaskBuilder & utils::TaskBuilder< OptionsImpl >::Critical ( )
inline

Set "critical" flag for the new task.

See also
engine::TaskBase::Importance

Definition at line 192 of file task_builder.hpp.

◆ Deadline()

template<typename OptionsImpl>
TaskBuilder & utils::TaskBuilder< OptionsImpl >::Deadline ( engine::Deadline deadline)
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.

◆ HideSpan()

template<typename OptionsImpl>
TaskBuilderHideSpan utils::TaskBuilder< OptionsImpl >::HideSpan ( )
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.

◆ NoSpan()

template<typename OptionsImpl>
TaskBuilderNoSpan utils::TaskBuilder< OptionsImpl >::NoSpan ( )
inlinenodiscard

The following call to Build will spawn a task without any tracing::Span.

See also
engine::AsyncNoTracing()

Definition at line 184 of file task_builder.hpp.

◆ SpanName()

template<typename OptionsImpl>
TaskBuilderWithSpan utils::TaskBuilder< OptionsImpl >::SpanName ( std::string && name)
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.

◆ TaskProcessor()

template<typename OptionsImpl>
TaskBuilder & utils::TaskBuilder< OptionsImpl >::TaskProcessor ( engine::TaskProcessor & tp)
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.

Friends And Related Symbol Documentation

◆ TaskBuilder

template<typename OptionsImpl>
template<typename OtherOptions>
friend class TaskBuilder
friend

Ensures that TaskBuilder{} produces a TaskBuilderBase.

Definition at line 243 of file task_builder.hpp.


The documentation for this class was generated from the following file: