Commit 7c600a5a authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Resolve the circular dependency between folly/futures/detail/Core.h and Future.h and Promise.h

Summary: Do this by moving the two helpers that need to refer to them into `folly/futures/helpers.h`.

Reviewed By: yfeldblum

Differential Revision: D5179109

fbshipit-source-id: bdb319ff3432d3629a955c1390dc8bf6f27f4ce6
parent e41df7e9
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
#include <folly/Optional.h> #include <folly/Optional.h>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/Try.h> #include <folly/Try.h>
#include <folly/futures/Future.h> #include <folly/futures/FutureException.h>
#include <folly/futures/Promise.h>
#include <folly/futures/detail/FSM.h> #include <folly/futures/detail/FSM.h>
#include <folly/io/async/Request.h> #include <folly/io/async/Request.h>
...@@ -422,45 +421,6 @@ class Core final { ...@@ -422,45 +421,6 @@ class Core final {
std::function<void(exception_wrapper const&)> interruptHandler_ {nullptr}; std::function<void(exception_wrapper const&)> interruptHandler_ {nullptr};
}; };
template <typename... Ts>
struct CollectAllVariadicContext {
CollectAllVariadicContext() {}
template <typename T, size_t I>
inline void setPartialResult(Try<T>& t) {
std::get<I>(results) = std::move(t);
}
~CollectAllVariadicContext() {
p.setValue(std::move(results));
}
Promise<std::tuple<Try<Ts>...>> p;
std::tuple<Try<Ts>...> results;
typedef Future<std::tuple<Try<Ts>...>> type;
};
template <typename... Ts>
struct CollectVariadicContext {
CollectVariadicContext() {}
template <typename T, size_t I>
inline void setPartialResult(Try<T>& t) {
if (t.hasException()) {
if (!threw.exchange(true)) {
p.setException(std::move(t.exception()));
}
} else if (!threw) {
std::get<I>(results) = std::move(t);
}
}
~CollectVariadicContext() noexcept {
if (!threw.exchange(true)) {
p.setValue(unwrapTryTuple(std::move(results)));
}
}
Promise<std::tuple<Ts...>> p;
std::tuple<folly::Try<Ts>...> results;
std::atomic<bool> threw {false};
typedef Future<std::tuple<Ts...>> type;
};
template <template <typename...> class T, typename... Ts> template <template <typename...> class T, typename... Ts>
void collectVariadicHelper(const std::shared_ptr<T<Ts...>>& /* ctx */) { void collectVariadicHelper(const std::shared_ptr<T<Ts...>>& /* ctx */) {
// base case // base case
......
...@@ -15,11 +15,58 @@ ...@@ -15,11 +15,58 @@
*/ */
#pragma once #pragma once
#include <folly/futures/Future.h> #include <atomic>
#include <tuple>
#include <utility>
#include <folly/Portability.h> #include <folly/Portability.h>
#include <folly/Try.h>
#include <folly/futures/Future.h>
#include <folly/futures/Promise.h>
namespace folly { namespace folly {
namespace detail {
template <typename... Ts>
struct CollectAllVariadicContext {
CollectAllVariadicContext() {}
template <typename T, size_t I>
inline void setPartialResult(Try<T>& t) {
std::get<I>(results) = std::move(t);
}
~CollectAllVariadicContext() {
p.setValue(std::move(results));
}
Promise<std::tuple<Try<Ts>...>> p;
std::tuple<Try<Ts>...> results;
typedef Future<std::tuple<Try<Ts>...>> type;
};
template <typename... Ts>
struct CollectVariadicContext {
CollectVariadicContext() {}
template <typename T, size_t I>
inline void setPartialResult(Try<T>& t) {
if (t.hasException()) {
if (!threw.exchange(true)) {
p.setException(std::move(t.exception()));
}
} else if (!threw) {
std::get<I>(results) = std::move(t);
}
}
~CollectVariadicContext() noexcept {
if (!threw.exchange(true)) {
p.setValue(unwrapTryTuple(std::move(results)));
}
}
Promise<std::tuple<Ts...>> p;
std::tuple<folly::Try<Ts>...> results;
std::atomic<bool> threw{false};
typedef Future<std::tuple<Ts...>> type;
};
}
/// This namespace is for utility functions that would usually be static /// This namespace is for utility functions that would usually be static
/// members of Future, except they don't make sense there because they don't /// members of Future, except they don't make sense there because they don't
/// depend on the template type (rather, on the type of their arguments in /// depend on the template type (rather, on the type of their arguments in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment