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

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

Detailed Description

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

TaskLocalVariable is a per-coroutine variable of arbitrary type.

It is an alternative to thread_local, but per-task instead of per-thread.

The order of destruction of task-local variables is inverse to the order of initialization.

Definition at line 23 of file local_variable.hpp.

Public Member Functions

T & operator* ()
 Get the instance of the variable for the current coroutine. Initializes (default constructs) the variable if it was not previously initialized.
 
T * operator-> ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
T * GetOptional () noexcept
 Get the variable instance for the current task.
 

Member Function Documentation

◆ GetOptional()

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

Get the variable instance for the current task.

Returns
the variable or nullptr if variable was not initialized.

Definition at line 39 of file local_variable.hpp.

◆ operator*()

template<typename T >
T & engine::TaskLocalVariable< T >::operator* ( )

Get the instance of the variable for the current coroutine. Initializes (default constructs) the variable if it was not previously initialized.

Note
Must be called from a coroutine, otherwise it is UB.

Definition at line 51 of file local_variable.hpp.

◆ operator->()

template<typename T >
T * engine::TaskLocalVariable< T >::operator-> ( )

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 57 of file local_variable.hpp.


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