Commit ab24ce0c authored by Sven Over's avatar Sven Over Committed by Facebook Github Bot

fix `folly::via` for callables returning SemiFuture

Summary:
When passing a callable to `folly::via` that returns a SemiFuture,
via should return a Future. The implementation does the correct thing
but the declaration's return type is not correct. This diff fixes that.

Reviewed By: yfeldblum

Differential Revision: D9219041

fbshipit-source-id: e61544231e7846c713ff43394c3bf5d1aae18233
parent 1d3ee8c5
......@@ -1297,8 +1297,8 @@ Future<T>::onError(F&& func) {
}
template <class Func>
auto via(Executor* x, Func&& func)
-> Future<typename isFuture<decltype(std::declval<Func>()())>::Inner> {
auto via(Executor* x, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner> {
// TODO make this actually more performant. :-P #7260175
return via(x).then(std::forward<Func>(func));
}
......
......@@ -274,8 +274,8 @@ inline Future<Unit> via(
/// This is semantically equivalent to via(executor).then(func), but
/// easier to read and slightly more efficient.
template <class Func>
auto via(Executor*, Func&& func)
-> Future<typename isFuture<decltype(std::declval<Func>()())>::Inner>;
auto via(Executor*, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner>;
/** When all the input Futures complete, the returned Future will complete.
Errors do not cause early termination; this Future will always succeed
......
......@@ -603,6 +603,11 @@ TEST(ViaFunc, future) {
.getVia(&x));
}
TEST(ViaFunc, semi_future) {
ManualExecutor x;
EXPECT_EQ(42, via(&x, [] { return makeSemiFuture(42); }).getVia(&x));
}
TEST(ViaFunc, voidFuture) {
ManualExecutor x;
int count = 0;
......
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