Commit 6afcbf48 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Remove Promise::getFuture from Future-inl.h 2/4 - waitImpl

Summary: Replace calls to Promise::getFuture in waitImpl with getSemiFuture. There is a slight behavioural change here in that we now set the executor on the returned future, but this appears to be the correct behaviour.

Reviewed By: yfeldblum

Differential Revision: D7104627

fbshipit-source-id: fd19c3f6884b560f7d5ea1276f3c80c082dfc53d
parent a440441d
......@@ -1543,6 +1543,19 @@ void waitImpl(FutureType& f) {
assert(f.isReady());
}
template <class T>
void convertFuture(SemiFuture<T>&& sf, Future<T>& f) {
// Carry executor from f, inserting an inline executor if it did not have one
auto* currentExecutor = f.getExecutor();
f = std::move(sf).via(
currentExecutor ? currentExecutor : &folly::InlineExecutor::instance());
}
template <class T>
void convertFuture(SemiFuture<T>&& sf, SemiFuture<T>& f) {
f = std::move(sf);
}
template <class FutureType, typename T = typename FutureType::value_type>
void waitImpl(FutureType& f, Duration dur) {
// short-circuit if there's nothing to do
......@@ -1551,13 +1564,13 @@ void waitImpl(FutureType& f, Duration dur) {
}
Promise<T> promise;
auto ret = promise.getFuture();
auto ret = promise.getSemiFuture();
auto baton = std::make_shared<FutureBatonType>();
f.setCallback_([baton, promise = std::move(promise)](Try<T>&& t) mutable {
promise.setTry(std::move(t));
baton->post();
});
f = std::move(ret);
convertFuture(std::move(ret), f);
if (baton->try_wait_for(dur)) {
assert(f.isReady());
}
......
......@@ -193,6 +193,8 @@ class FutureBase {
typename std::enable_if<R::ReturnsFuture::value, typename R::Return>::type
thenImplementation(F&& func, futures::detail::argResult<isTry, F, Args...>);
};
template <class T>
void convertFuture(SemiFuture<T>&& sf, Future<T>& f);
} // namespace detail
} // namespace futures
......@@ -814,6 +816,11 @@ class Future : private futures::detail::FutureBase<T> {
/// predicate behaves like std::function<bool(void)>
template <class P, class F>
friend Future<Unit> whileDo(P&& predicate, F&& thunk);
template <class FT>
friend void futures::detail::convertFuture(
SemiFuture<FT>&& sf,
Future<FT>& f);
};
} // namespace folly
......
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