userver: engine::TaskInheritedVariable< T > Class Template Reference
Loading...
Searching...
No Matches
engine::TaskInheritedVariable< T > Class Template Referencefinal

#include <userver/engine/task/inherited_variable.hpp>

Detailed Description

template<typename T>
class engine::TaskInheritedVariable< T >

TaskInheritedVariable is a per-coroutine variable of arbitrary type.

These are like engine::TaskLocalVariable, but the variable instances are inherited by child tasks created via utils::Async.

By default a variable is inherited only by regular child tasks, not utils::AsyncBackground. This behavior can be changed by passing a different priority to the constructor.

The order of destruction of task-inherited variables is unspecified.

Definition at line 28 of file inherited_variable.hpp.

Public Member Functions

 TaskInheritedVariable ()
 Create a task-inherited variable with TaskInheritedVariablePriority::kNormal.
 TaskInheritedVariable (TaskInheritedVariablePriority priority)
 Create a task-inherited variable with the specified inheritance priority.
const T * GetOptional () const noexcept
 Get the variable instance for the current task.
const T & Get () const
 Get the variable instance for the current task.
template<typename... Args>
void Emplace (Args &&... args)
 Sets or replaces the T variable instance.
void Set (T &&value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Set (const T &value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Erase ()
 Hide the variable so that it is no longer accessible from the current or new child tasks.

Constructor & Destructor Documentation

◆ TaskInheritedVariable() [1/2]

template<typename T>
engine::TaskInheritedVariable< T >::TaskInheritedVariable ( )
inline

Create a task-inherited variable with TaskInheritedVariablePriority::kNormal.

Definition at line 34 of file inherited_variable.hpp.

◆ TaskInheritedVariable() [2/2]

template<typename T>
engine::TaskInheritedVariable< T >::TaskInheritedVariable ( TaskInheritedVariablePriority priority)
inlineexplicit

Create a task-inherited variable with the specified inheritance priority.

Definition at line 39 of file inherited_variable.hpp.

Member Function Documentation

◆ Emplace()

template<typename T>
template<typename... Args>
void engine::TaskInheritedVariable< T >::Emplace ( Args &&... args)
inline

Sets or replaces the T variable instance.

Definition at line 53 of file inherited_variable.hpp.

◆ Erase()

template<typename T>
void engine::TaskInheritedVariable< T >::Erase ( )
inline

Hide the variable so that it is no longer accessible from the current or new child tasks.

Note
The variable might not actually be destroyed immediately.

Definition at line 66 of file inherited_variable.hpp.

◆ Get()

template<typename T>
const T & engine::TaskInheritedVariable< T >::Get ( ) const
inline

Get the variable instance for the current task.

Exceptions
std::runtime_errorif variable was not set.

Definition at line 49 of file inherited_variable.hpp.

◆ GetOptional()

template<typename T>
const T * engine::TaskInheritedVariable< T >::GetOptional ( ) const
inlinenoexcept

Get the variable instance for the current task.

Returns
the variable or nullptr if variable was not set.

Definition at line 45 of file inherited_variable.hpp.

◆ Set() [1/2]

template<typename T>
void engine::TaskInheritedVariable< T >::Set ( const T & value)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 61 of file inherited_variable.hpp.

◆ Set() [2/2]

template<typename T>
void engine::TaskInheritedVariable< T >::Set ( T && value)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 58 of file inherited_variable.hpp.


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