diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 927a314..00cfba2 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -620,13 +620,13 @@ struct CollectContext { Optional >::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> p; std::vector results; - std::atomic count; + std::atomic count, success_count; std::atomic_bool threw; typedef std::vector result_type; @@ -647,10 +647,10 @@ struct CollectContext { template <> struct CollectContext { - explicit CollectContext(int n) : count(0), threw(false) {} + explicit CollectContext(int n) : count(0), success_count(0), threw(false) {} Promise p; - std::atomic count; + std::atomic count, success_count; std::atomic_bool threw; typedef void result_type; @@ -690,7 +690,6 @@ collect(InputIterator first, InputIterator last) { assert(i < n); auto& f = *first; f.setCallback_([ctx, i, n](Try t) { - auto c = ++ctx->count; if (t.hasException()) { if (!ctx->threw.exchange(true)) { @@ -698,12 +697,12 @@ collect(InputIterator first, InputIterator last) { } } 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; } });