userver
C++ Async Framework
Loading...
Searching...
No Matches
task.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/engine/task/task.hpp
4
/// @brief @copybrief engine::Task
5
6
#
include
<
userver
/
engine
/
task
/
task_base
.
hpp
>
7
8
USERVER_NAMESPACE_BEGIN
9
10
namespace
engine {
11
12
/// @brief Asynchronous task that has a unique ownership of the payload.
13
///
14
/// See engine::TaskWithResult for a type that could return a value or
15
/// report an exception from the payload.
16
class
[[nodiscard]]
Task
:
public
TaskBase
{
17
public
:
18
/// @brief Default constructor
19
///
20
/// Creates an invalid task.
21
Task
();
22
23
/// @brief If the task is still valid and is not finished, cancels it and
24
/// waits until it finishes.
25
~
Task
();
26
27
/// @brief Moves the other task into this, leaving the other in an invalid
28
/// state.
29
Task
(
Task
&& other)
noexcept
;
30
31
/// @brief If this Task is still valid and is not finished, cancels it and
32
/// waits until it finishes before moving the other. Otherwise just moves the
33
/// other task into this, leaving the other in invalid state.
34
Task
&
operator
=(
Task
&& other)
noexcept
;
35
36
Task(
const
Task
&) =
delete
;
37
Task
& operator=(
const
Task
&) =
delete
;
38
39
/// @brief Detaches task, allowing it to continue execution out of scope;
40
/// memory safety is much better with concurrent::BackgroundTaskStorage
41
///
42
/// @note After detach, Task becomes invalid
43
///
44
/// @warning Variables, which are captured by reference for this task in
45
/// `Async*`, should outlive the task execution. This is hard to achieve in
46
/// general, detached tasks may outlive all the components!
47
/// Use concurrent::BackgroundTaskStorage as a safe and efficient alternative
48
/// to calling Detach().
49
void
Detach
() &&;
50
51
/// @cond
52
// For internal use only.
53
impl::ContextAccessor* TryGetContextAccessor()
noexcept
;
54
/// @endcond
55
56
protected
:
57
/// @cond
58
// For internal use only.
59
explicit
Task(impl::TaskContextHolder&& context);
60
/// @endcond
61
};
62
63
}
// namespace engine
64
65
USERVER_NAMESPACE_END
userver
engine
task
task.hpp
Generated on Wed May 15 2024 22:19:41 for userver by
Doxygen
1.10.0