userver: concurrent::BackgroundTaskStorageCore Class Reference
Loading...
Searching...
No Matches
concurrent::BackgroundTaskStorageCore Class Referencefinal

#include <userver/concurrent/background_task_storage.hpp>

Detailed Description

A version of concurrent::BackgroundTaskStorage for advanced use cases (e.g. driver internals) that can take the ownership of any kind of task.

Definition at line 21 of file background_task_storage.hpp.

Public Member Functions

 BackgroundTaskStorageCore ()
 Creates an empty BTS.
 BackgroundTaskStorageCore (BackgroundTaskStorageCore &&)=delete
BackgroundTaskStorageCoreoperator= (BackgroundTaskStorageCore &&)=delete
void CancelAndWait () noexcept
 Explicitly cancel and wait for the tasks. New tasks must not be launched after this call returns.
void WaitAndDisposeSlow () noexcept
 Wait for the remaining tasks to complete without cancelling them. New tasks must not be launched after this call returns.
void Detach (engine::Task &&task)
 Detaches task, allowing it to continue execution out of scope. It will be cancelled and waited for on BTS destruction.
std::int64_t ActiveTasksApprox () const noexcept

Member Function Documentation

◆ ActiveTasksApprox()

std::int64_t concurrent::BackgroundTaskStorageCore::ActiveTasksApprox ( ) const
noexcept
Returns
Approximate number of currently active tasks.

Can be called from a coroutine or a non-coroutine thread. Cannot be called after CancelAndWait or WaitAndDisposeSlow has been called.

◆ CancelAndWait()

void concurrent::BackgroundTaskStorageCore::CancelAndWait ( )
noexcept

Explicitly cancel and wait for the tasks. New tasks must not be launched after this call returns.

More precisely, new tasks must not be launched once this call is completed, but can be launched in the process of waiting for the remaining tasks. This means that one detached task is allowed to spawn another detached task into the same BTS, which will immediately be cancelled and for which this call will wait as well.

Can only be called from a coroutine.

◆ Detach()

void concurrent::BackgroundTaskStorageCore::Detach ( engine::Task && task)

Detaches task, allowing it to continue execution out of scope. It will be cancelled and waited for on BTS destruction.

Note
After detach, Task becomes invalid

Can be called from a coroutine or a non-coroutine thread. Cannot be called after CancelAndWait or WaitAndDisposeSlow has been called.

◆ WaitAndDisposeSlow()

void concurrent::BackgroundTaskStorageCore::WaitAndDisposeSlow ( )
noexcept

Wait for the remaining tasks to complete without cancelling them. New tasks must not be launched after this call returns.

More precisely, new tasks must not be launched once this call is completed, but can be launched in the process of waiting for the remaining tasks. This means that one detached task is allowed to spawn another detached task into the same BTS, for which this call will wait as well.

Note
Running this method burns some CPU time (a few microseconds). Awaiting the tasks once on service shutdown, or even periodically, is okay, but don't use BackgroundTaskStorage as a substitute for std::vector<Task> in handlers, because it is less efficient.

Can only be called from a coroutine.


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