userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
conflated_event_channel.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <atomic>
7
#include <string>
8
#include <utility>
9
10
#include <
userver/concurrent/async_event_channel.hpp
>
11
#include <
userver/engine/single_consumer_event.hpp
>
12
#include <
userver/engine/task/task_with_result.hpp
>
13
#include <
userver/utils/resource_scopes.hpp
>
14
15
USERVER_NAMESPACE_BEGIN
16
17
namespace
concurrent
{
18
29
class
ConflatedEventChannel :
private
AsyncEventChannel
<> {
30
public
:
31
explicit
ConflatedEventChannel(std::string name, OnRemoveCallback on_listener_removal = {});
32
~ConflatedEventChannel()
override
;
33
35
template
<
typename
... Args>
36
void
AddChannel
(
concurrent::AsyncEventSource<Args...>
& channel);
37
38
using
AsyncEventChannel
<>
::AddListener
;
39
51
template
<
typename
Class>
52
void
UpdateAndListen
(
utils::ResourceScopeStorage
& scopes, Class* obj, std::string_view name,
void
(Class::*func)());
53
54
void
SendEvent();
55
56
private
:
57
struct
Data final {
58
Data(
utils::ResourceScopeStorage
& scopes,
AsyncEventChannel<>
& channel);
59
~Data();
60
61
void
SendEvent();
62
63
template
<
typename
... Args>
64
void
OnChannelEvent(Args...) {
65
SendEvent();
66
}
67
68
utils::ResourceScopeStorage
& scopes;
69
const
std::string name;
70
std::atomic<bool> stop_flag{
false
};
71
engine::SingleConsumerEvent
event;
72
engine::TaskWithResult<void>
task;
73
};
74
75
utils::WithResourceScopes<Data>
data_;
76
};
77
78
template
<
typename
... Args>
79
void
ConflatedEventChannel::AddChannel
(
concurrent::AsyncEventSource<Args...>
& channel) {
80
auto
& data = *data_;
81
channel.
AddListener
(data.scopes, &data, data.name, &Data::OnChannelEvent<Args...>);
82
}
83
84
template
<
typename
Class>
85
void
ConflatedEventChannel::UpdateAndListen
(
86
utils::ResourceScopeStorage
& scopes,
87
Class* obj,
88
std::string_view name,
89
void
(Class::*func)()
90
) {
91
DoUpdateAndListen
(scopes, obj, name, func, [obj, func] { (obj->*func)(); });
92
}
93
94
}
// namespace concurrent
95
96
USERVER_NAMESPACE_END
userver
concurrent
conflated_event_channel.hpp
Generated on
for userver by
Doxygen
1.17.0