Commit 261d2494 authored by Adam Norton's avatar Adam Norton Committed by Facebook Github Bot

KeepAlive via functions

Summary: Add via helpers for KeepAlive argument

Reviewed By: yfeldblum

Differential Revision: D9617303

fbshipit-source-id: 4ace3ea5f48fd8fbed70bcdf7654a1435f5e1d72
parent 1723003c
......@@ -1309,6 +1309,12 @@ auto via(Executor* x, Func&& func) -> Future<
return via(x).then(std::forward<Func>(func));
}
template <class Func>
auto via(Executor::KeepAlive<> x, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner> {
return via(std::move(x)).then(std::forward<Func>(func));
}
// makeFuture
template <class T>
......@@ -1375,6 +1381,10 @@ Future<Unit> via(Executor* executor, int8_t priority) {
return makeFuture().via(executor, priority);
}
Future<Unit> via(Executor::KeepAlive<> executor, int8_t priority) {
return makeFuture().via(std::move(executor), priority);
}
namespace futures {
namespace detail {
......
......@@ -270,6 +270,10 @@ inline Future<Unit> via(
Executor* executor,
int8_t priority = Executor::MID_PRI);
inline Future<Unit> via(
Executor::KeepAlive<> executor,
int8_t priority = Executor::MID_PRI);
/// Execute a function via the given executor and return a future.
/// This is semantically equivalent to via(executor).then(func), but
/// easier to read and slightly more efficient.
......@@ -277,6 +281,10 @@ template <class Func>
auto via(Executor*, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner>;
template <class Func>
auto via(Executor::KeepAlive<>, 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
after all its Futures have finished (whether successfully or with an
......
......@@ -634,3 +634,13 @@ TEST(ViaFunc, moveOnly) {
EXPECT_EQ(42, via(&x, [intp = std::move(intp)] { return *intp; }).getVia(&x));
}
TEST(ViaFunc, valueKeepAlive) {
ManualExecutor x;
EXPECT_EQ(42, via(getKeepAliveToken(&x), [] { return 42; }).getVia(&x));
}
TEST(ViaFunc, thenValueKeepAlive) {
ManualExecutor x;
EXPECT_EQ(42, via(getKeepAliveToken(&x)).then([] { return 42; }).getVia(&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