userver: userver/drivers/subscribable_futures.hpp Source File
Loading...
Searching...
No Matches
subscribable_futures.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <boost/intrusive_ptr.hpp>
7#include <boost/smart_ptr/intrusive_ref_counter.hpp>
8
15
16USERVER_NAMESPACE_BEGIN
17
18namespace drivers {
19
20namespace impl {
21
22struct EventHolder final : boost::intrusive_ref_counter<EventHolder> {
23 engine::SingleConsumerEvent event{engine::SingleConsumerEvent::NoAutoReset{}};
24};
25
26} // namespace impl
27
40template <typename SubscribableFuture>
41class SubscribableFutureWrapper final {
42public:
43 explicit SubscribableFutureWrapper(SubscribableFuture&& future)
44 : original_future_(static_cast<SubscribableFuture&&>(future)),
46 {
47 original_future_.Subscribe([event_holder = event_holder_](auto&) { event_holder->event.Send(); });
48 }
49
51 SubscribableFuture& GetFuture() { return original_future_; }
52
61
66 if (event_holder_->event.WaitForEventUntil(deadline)) {
68 }
70 }
71
72private:
73 SubscribableFuture original_future_;
74 boost::intrusive_ptr<impl::EventHolder> event_holder_;
75};
76
85template <typename SubscribableFuture>
86void WaitForSubscribableFuture(SubscribableFuture&& future) {
88}
89
96template <typename SubscribableFuture>
98 SubscribableFuture&& future,
99 engine::Deadline deadline
100) {
102}
103
104} // namespace drivers
105
106USERVER_NAMESPACE_END