6#include <boost/intrusive_ptr.hpp>
7#include <boost/smart_ptr/intrusive_ref_counter.hpp>
9#include <userver/engine/deadline.hpp>
10#include <userver/engine/exception.hpp>
11#include <userver/engine/future_status.hpp>
12#include <userver/engine/single_consumer_event.hpp>
13#include <userver/engine/task/cancel.hpp>
14#include <userver/utils/make_intrusive_ptr.hpp>
16USERVER_NAMESPACE_BEGIN
22struct EventHolder
final : boost::intrusive_ref_counter<EventHolder> {
23 engine::SingleConsumerEvent event{engine::SingleConsumerEvent::NoAutoReset{}};
40template <
typename SubscribableFuture>
41class SubscribableFutureWrapper
final {
43 explicit SubscribableFutureWrapper(SubscribableFuture&& future)
44 : original_future_(
static_cast<SubscribableFuture&&>(future)),
45 event_holder_(utils::make_intrusive_ptr<impl::EventHolder>()) {
46 original_future_.Subscribe(
47 [event_holder = event_holder_](
auto&) { event_holder->event.Send(); });
51 SubscribableFuture&
GetFuture() {
return original_future_; }
67 if (event_holder_->event.WaitForEventUntil(deadline)) {
76 SubscribableFuture original_future_;
77 boost::intrusive_ptr<impl::EventHolder> event_holder_;
88template <
typename SubscribableFuture>
90 SubscribableFutureWrapper<SubscribableFuture&>{future}.Wait();
99template <
typename SubscribableFuture>
101 SubscribableFuture&& future, engine::Deadline deadline) {
102 return SubscribableFutureWrapper<SubscribableFuture&>{future}.TryWaitUntil(