20 #include <condition_variable>
22 #include <boost/thread/future.hpp>
24 #include "hazelcast/util/Preconditions.h"
81 class pipelining :
public std::enable_shared_from_this<pipelining<E>>
99 static std::shared_ptr<pipelining>
create(
int depth)
101 util::Preconditions::check_positive(depth,
"depth must be positive");
103 return std::shared_ptr<pipelining>(
new pipelining(depth));
118 std::vector<boost::optional<E>> result;
119 result.reserve(futures_.size());
120 auto result_futures = when_all(futures_.begin(), futures_.end());
121 for (
auto& f : result_futures.get()) {
122 result.emplace_back(f.get());
136 void add(boost::future<boost::optional<E>> future)
140 futures_.push_back(future.share());
146 util::Preconditions::check_positive(depth,
"depth must be positive"))
152 for (
auto& f : futures_) {
157 if (usedPermits >= permits_) {
158 decltype(futures_) outStandingFutures;
159 for (
auto& f : futures_) {
161 outStandingFutures.push_back(f);
165 if (!outStandingFutures.empty()) {
166 boost::when_any(outStandingFutures.begin(),
167 outStandingFutures.end())
174 std::vector<boost::shared_future<boost::optional<E>>> futures_;
static std::shared_ptr< pipelining > create(int depth)
Creates a Pipelining with the given depth.
std::vector< boost::optional< E > > results()
Returns the results.
void add(boost::future< boost::optional< E >> future)
Adds a future to this Pipelining or blocks until there is capacity to add the future to the Pipelinin...