Optional<T>
>::type VecT;
- explicit CollectContext(int n) : count(0), threw(false) {
+ explicit CollectContext(int n) : count(0), success_count(0), threw(false) {
results.resize(n);
}
Promise<std::vector<T>> p;
std::vector<VecT> results;
- std::atomic<size_t> count;
+ std::atomic<size_t> count, success_count;
std::atomic_bool threw;
typedef std::vector<T> result_type;
template <>
struct CollectContext<void> {
- explicit CollectContext(int n) : count(0), threw(false) {}
+ explicit CollectContext(int n) : count(0), success_count(0), threw(false) {}
Promise<void> p;
- std::atomic<size_t> count;
+ std::atomic<size_t> count, success_count;
std::atomic_bool threw;
typedef void result_type;
assert(i < n);
auto& f = *first;
f.setCallback_([ctx, i, n](Try<T> t) {
- auto c = ++ctx->count;
if (t.hasException()) {
if (!ctx->threw.exchange(true)) {
}
} else if (!ctx->threw) {
ctx->addResult(i, t);
- if (c == n) {
+ if (++ctx->success_count == n) {
ctx->setValue();
}
}
- if (c == n) {
+ if (++ctx->count == n) {
delete ctx;
}
});