Commit 3ae1ec3c authored by Hannes Roth's avatar Hannes Roth Committed by afrind

(Wangle) Swap order of Try<T> and T matching

Summary:
See the test case and D1958860.

I don't really know why I chose one over the other. This fixes a bug. So
it's better?

Test Plan: Run all the tests?

Reviewed By: yfeldblum@fb.com

Subscribers: folly-diffs@, jsedgwick, yfeldblum, chalfant, over

FB internal diff: D1960740

Signature: t1:1960740:1427927644:25093b049a1519d7c869ee7043f3caced4cc971e
parent 62e15017
......@@ -98,16 +98,16 @@ struct callableResult {
typedef typename std::conditional<
callableWith<F>::value,
detail::argResult<false, F>,
typename std::conditional<
callableWith<F, Try<T>&&>::value,
detail::argResult<true, F, Try<T>&&>,
typename std::conditional<
callableWith<F, Try<T>&>::value,
detail::argResult<true, F, Try<T>&>,
typename std::conditional<
callableWith<F, T&&>::value,
detail::argResult<false, F, T&&>,
detail::argResult<false, F, T&>>::type>::type>::type>::type Arg;
typename std::conditional<
callableWith<F, T&>::value,
detail::argResult<false, F, T&>,
typename std::conditional<
callableWith<F, Try<T>&&>::value,
detail::argResult<true, F, Try<T>&&>,
detail::argResult<true, F, Try<T>&>>::type>::type>::type>::type Arg;
typedef isFuture<typename Arg::Result> ReturnsFuture;
typedef Future<typename ReturnsFuture::Inner> Return;
};
......
......@@ -28,6 +28,7 @@
#include <folly/futures/Future.h>
#include <folly/futures/ManualExecutor.h>
#include <folly/futures/DrivableExecutor.h>
#include <folly/dynamic.h>
#include <folly/MPMCQueue.h>
#include <folly/io/async/EventBase.h>
......@@ -1311,6 +1312,20 @@ TEST(Future, ImplicitConstructor) {
//auto f2 = []() -> Future<void> { }();
}
TEST(Future, thenDynamic) {
// folly::dynamic has a constructor that takes any T, this test makes
// sure that we call the then lambda with folly::dynamic and not
// Try<folly::dynamic> because that then fails to compile
Promise<folly::dynamic> p;
Future<folly::dynamic> f = p.getFuture().then(
[](const folly::dynamic& d) {
return folly::dynamic(d.asInt() + 3);
}
);
p.setValue(2);
EXPECT_EQ(f.get(), 5);
}
TEST(Future, via_then_get_was_racy) {
ThreadExecutor x;
std::unique_ptr<int> val = folly::via(&x)
......
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