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

Remove Promise::getFuture from Future-inl.h 3/4 - onError

Summary: Replaces calls to Promise::getFuture in onError calls. Modifies the returned future to complete on the same executor as the caller. No assumption that the future already has an executor (though it should in principle, the codebase is not ready for that yet).

Reviewed By: yfeldblum

Differential Revision: D7104850

fbshipit-source-id: ea152102f8ecd612e322b98a54d9440495b14bf8
parent c3a1cd78
......@@ -835,7 +835,7 @@ Future<T>::onError(F&& func) {
Promise<T> p;
p.core_->setInterruptHandlerNoLock(this->core_->getInterruptHandler());
auto f = p.getFuture();
auto sf = p.getSemiFuture();
this->setCallback_(
[state = futures::detail::makeCoreCallbackState(
......@@ -847,7 +847,10 @@ Future<T>::onError(F&& func) {
}
});
return f;
// Allow for applying to future with null executor while this is still
// possible.
auto* e = this->getExecutor();
return std::move(sf).via(e ? e : &folly::InlineExecutor::instance());
}
// onError where the callback returns Future<T>
......@@ -868,7 +871,7 @@ Future<T>::onError(F&& func) {
Exn;
Promise<T> p;
auto f = p.getFuture();
auto sf = p.getSemiFuture();
this->setCallback_(
[state = futures::detail::makeCoreCallbackState(
......@@ -887,7 +890,10 @@ Future<T>::onError(F&& func) {
}
});
return f;
// Allow for applying to future with null executor while this is still
// possible.
auto* e = this->getExecutor();
return std::move(sf).via(e ? e : &folly::InlineExecutor::instance());
}
template <class T>
......@@ -919,7 +925,7 @@ Future<T>::onError(F&& func) {
"Return type of onError callback must be T or Future<T>");
Promise<T> p;
auto f = p.getFuture();
auto sf = p.getSemiFuture();
this->setCallback_(
[state = futures::detail::makeCoreCallbackState(
std::move(p), std::forward<F>(func))](Try<T> t) mutable {
......@@ -937,7 +943,10 @@ Future<T>::onError(F&& func) {
}
});
return f;
// Allow for applying to future with null executor while this is still
// possible.
auto* e = this->getExecutor();
return std::move(sf).via(e ? e : &folly::InlineExecutor::instance());
}
// onError(exception_wrapper) that returns T
......@@ -954,7 +963,7 @@ Future<T>::onError(F&& func) {
"Return type of onError callback must be T or Future<T>");
Promise<T> p;
auto f = p.getFuture();
auto sf = p.getSemiFuture();
this->setCallback_(
[state = futures::detail::makeCoreCallbackState(
std::move(p), std::forward<F>(func))](Try<T>&& t) mutable {
......@@ -966,7 +975,10 @@ Future<T>::onError(F&& func) {
}
});
return f;
// Allow for applying to future with null executor while this is still
// possible.
auto* e = this->getExecutor();
return std::move(sf).via(e ? e : &folly::InlineExecutor::instance());
}
template <class Func>
......
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