Commit 4813f785 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Modify thenTry to fail correctly with a parameterless lambda

Summary: Removes support for thenTry to accept a lambda with no parameter list and fail to compile with no arguments.

Reviewed By: yfeldblum

Differential Revision: D9011934

fbshipit-source-id: ec29b0c3d9475e7d2c566469b0ee333f0dc05738
parent 82fb08de
...@@ -1078,7 +1078,10 @@ template <class T> ...@@ -1078,7 +1078,10 @@ template <class T>
template <typename F> template <typename F>
Future<typename futures::detail::tryCallableResult<T, F>::value_type> Future<typename futures::detail::tryCallableResult<T, F>::value_type>
Future<T>::thenTry(F&& func) && { Future<T>::thenTry(F&& func) && {
return std::move(*this).then(std::forward<F>(func)); return std::move(*this).then(
[f = std::forward<F>(func)](folly::Try<T>&& t) mutable {
return std::forward<F>(f)(std::move(t));
});
} }
template <class T> template <class T>
......
...@@ -1232,6 +1232,11 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1232,6 +1232,11 @@ class Future : private futures::detail::FutureBase<T> {
Future<typename futures::detail::tryCallableResult<T, F>::value_type> thenTry( Future<typename futures::detail::tryCallableResult<T, F>::value_type> thenTry(
F&& func) &&; F&& func) &&;
template <typename R, typename... Args>
auto thenTry(R (&func)(Args...)) && {
return std::move(*this).thenTry(&func);
}
/// When this Future has completed, execute func which is a function that /// When this Future has completed, execute func which is a function that
/// can be called with `T&&` (often a lambda with parameter type /// can be called with `T&&` (often a lambda with parameter type
/// `auto&&` or `auto`). /// `auto&&` or `auto`).
......
...@@ -950,8 +950,8 @@ static folly::Future<std::string> doWorkStaticTry(Try<std::string>&& t) { ...@@ -950,8 +950,8 @@ static folly::Future<std::string> doWorkStaticTry(Try<std::string>&& t) {
TEST(Future, thenTrythenValue) { TEST(Future, thenTrythenValue) {
auto f = auto f =
makeFuture<std::string>("0") makeFuture()
.thenTry([]() { return makeFuture<std::string>("1"); }) .thenTry([](auto&&) { return makeFuture<std::string>("1"); })
.thenTry( .thenTry(
[](Try<std::string>&& t) { return makeFuture(t.value() + ";2"); }) [](Try<std::string>&& t) { return makeFuture(t.value() + ";2"); })
.thenTry([](const Try<std::string>&& t) { .thenTry([](const Try<std::string>&& t) {
......
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