34#include <seastar/core/future.hh>
35#include <seastar/core/shared_ptr.hh>
36#include <seastar/util/modules.hh>
41template <
class Sequence>
53 void done(std::size_t index) {
59 auto get_future() {
return _promise.
get_future(); }
77template <
class FutureIterator>
78requires requires (FutureIterator i) { { *i++ };
requires is_future<std::remove_reference_t<
decltype(*i)>>::value; }
79auto when_any(FutureIterator begin, FutureIterator end)
noexcept
84 return make_ready_future<ReturnType>();
87 result.futures.reserve(std::distance(begin, end));
88 auto waiter_obj = make_lw_shared<internal::waiter>();
90 for (
auto it = begin; it != end; ++it) {
91 if (it->available()) {
92 result.futures.push_back(std::move(*it));
93 waiter_obj->done(index);
95 result.futures.push_back(it->finally([waiter_obj, index] {
96 waiter_obj->done(index);
101 return waiter_obj->get_future().then(
102 [result = std::move(result)](std::size_t index)
mutable {
103 result.index = index;
104 return std::move(result);
111template <
class... Futures, std::size_t... I>
112future<when_any_result<std::tuple<Futures...>>>
113when_any_impl(std::index_sequence<I...>, Futures&&... futs)
noexcept
115 auto waiter_obj = make_lw_shared<waiter>();
116 auto attach_notifier = [&](
auto&& fut,
size_t index) {
117 if (fut.available()) {
118 waiter_obj->done(index);
119 return std::move(fut);
122 return fut.finally([waiter_obj, index] { waiter_obj->done(index); });
127 when_any_result<std::tuple<Futures...>>{0, std::make_tuple(attach_notifier(std::forward<Futures>(futs), I)...)};
128 return waiter_obj->get_future().then([result = std::move(result)](std::size_t index)
mutable {
129 result.index = index;
130 return std::move(result);
150template <
class... FutOrFuncs>
151auto when_any(FutOrFuncs&&... fut_or_funcs)
noexcept
153 return internal::when_any_impl(std::make_index_sequence<
sizeof...(FutOrFuncs)>{},
154 futurize_invoke_if_func(std::forward<FutOrFuncs>(fut_or_funcs))...);
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
promise - allows a future value to be made available at a later time.
Definition: future.hh:934
void set_value(A &&... a) noexcept
Sets the promises value.
Definition: future.hh:990
future< T > get_future() noexcept
Gets the promise's associated future.
Definition: future.hh:1926
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
auto when_any(FutureIterator begin, FutureIterator end) noexcept -> future< when_any_result< std::vector< std::decay_t< typename std::iterator_traits< FutureIterator >::value_type > > > >
Definition: when_any.hh:79
Definition: when_any.hh:42