Commit 46af81b6 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Split SemiFuture and Future into separate types. Add BasicFuture shared between them.

Summary:
To avoid the risk of bugs caused by a Future being cast to a SemiFuture, and losing some of the properties in the process, this splits SemiFuture and Future into unrelated types, sharing a private superclass for code reuse.
 * Add BasicFuture in futures::detail
 * Make superclass privately inherited.
 * Unset executor when constructing SemiFuture from Future.

Reviewed By: yfeldblum

Differential Revision: D6177780

fbshipit-source-id: dea3116aeec0572bb973c2a561e17785199e86f2
parent cceed93a
This diff is collapsed.
This diff is collapsed.
...@@ -29,6 +29,8 @@ template <class T> class Future; ...@@ -29,6 +29,8 @@ template <class T> class Future;
namespace futures { namespace futures {
namespace detail { namespace detail {
template <class T>
class FutureBase;
struct EmptyConstruct {}; struct EmptyConstruct {};
template <typename T, typename F> template <typename T, typename F>
class CoreCallbackState; class CoreCallbackState;
...@@ -110,8 +112,11 @@ class Promise { ...@@ -110,8 +112,11 @@ class Promise {
private: private:
typedef typename Future<T>::corePtr corePtr; typedef typename Future<T>::corePtr corePtr;
template <class> template <class>
friend class futures::detail::FutureBase;
template <class>
friend class SemiFuture; friend class SemiFuture;
template <class> friend class Future; template <class>
friend class Future;
template <class, class> template <class, class>
friend class futures::detail::CoreCallbackState; friend class futures::detail::CoreCallbackState;
......
...@@ -203,7 +203,7 @@ TEST(SemiFuture, MakeFutureFromSemiFutureLValue) { ...@@ -203,7 +203,7 @@ TEST(SemiFuture, MakeFutureFromSemiFutureLValue) {
Promise<int> p; Promise<int> p;
std::atomic<int> result{0}; std::atomic<int> result{0};
auto f = SemiFuture<int>{p.getFuture()}; auto f = SemiFuture<int>{p.getFuture()};
auto future = f.via(&e).then([&](int value) { auto future = std::move(f).via(&e).then([&](int value) {
result = value; result = value;
return value; return value;
}); });
......
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