userver: utils::TaskBuilder Class Reference
Loading...
Searching...
No Matches
utils::TaskBuilder Class Referencefinal

#include <userver/utils/task_builder.hpp>

Detailed Description

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::AsyncNoSpan.

See also
intro_tasks

Definition at line 27 of file task_builder.hpp.

Public Member Functions

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

Member Function Documentation

◆ Background()

TaskBuilder & utils::TaskBuilder::Background ( )

The following call to Build will spawn a background task without propagating engine::TaskInheritedVariable. tracing::Span and baggage::Baggage are inherited.

◆ Build()

template<typename Function, typename... Args>
auto utils::TaskBuilder::Build ( Function && f,
Args &&... args )

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 127 of file task_builder.hpp.

◆ BuildShared()

template<typename Function, typename... Args>
auto utils::TaskBuilder::BuildShared ( Function && f,
Args &&... args )

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 133 of file task_builder.hpp.

◆ Critical()

TaskBuilder & utils::TaskBuilder::Critical ( )

Set "critical" flag for the new task.

See also
engine::TaskBase::Importance

◆ Deadline()

TaskBuilder & utils::TaskBuilder::Deadline ( engine::Deadline deadline)

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.

◆ HideSpan()

TaskBuilder & utils::TaskBuilder::HideSpan ( )

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.

◆ NoSpan()

TaskBuilder & utils::TaskBuilder::NoSpan ( )

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

See also
engine::AsyncNoSpan()

◆ SpanName()

TaskBuilder & utils::TaskBuilder::SpanName ( std::string && name)

The following call to Build will spawn a task with tracing::Span with the passed name.

◆ TaskProcessor()

TaskBuilder & utils::TaskBuilder::TaskProcessor ( engine::TaskProcessor & tp)

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.


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