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

Move getTry to subclasses.

Summary:
Move getTry from FutureBase to Future and SemiFuture.

Make SemiFuture version move the result out for consistency with get.

Reviewed By: yfeldblum

Differential Revision: D6638561

fbshipit-source-id: 551c0f06ed52ef6d8976a5971a5e90b3ab793da0
parent d0da61c2
......@@ -208,12 +208,12 @@ bool FutureBase<T>::isReady() const {
template <class T>
bool FutureBase<T>::hasValue() {
return getTry().hasValue();
return core_->getTry().hasValue();
}
template <class T>
bool FutureBase<T>::hasException() {
return getTry().hasException();
return core_->getTry().hasException();
}
template <class T>
......@@ -224,13 +224,6 @@ void FutureBase<T>::detach() {
}
}
template <class T>
Try<T>& FutureBase<T>::getTry() {
throwIfInvalid();
return core_->getTry();
}
template <class T>
void FutureBase<T>::throwIfInvalid() const {
if (!core_) {
......@@ -1441,6 +1434,12 @@ T SemiFuture<T>::get(Duration dur) && {
}
}
template <class T>
Try<T> SemiFuture<T>::getTry() && {
wait();
return std::move(this->core_->getTry());
}
template <class T>
Future<T>& Future<T>::wait() & {
futures::detail::waitImpl(*this);
......@@ -1492,6 +1491,13 @@ T Future<T>::get(Duration dur) {
}
}
template <class T>
Try<T>& Future<T>::getTry() {
throwIfInvalid();
return this->core_->getTry();
}
template <class T>
T Future<T>::getVia(DrivableExecutor* e) {
return std::move(waitVia(e).value());
......
......@@ -106,9 +106,6 @@ class FutureBase {
/// sugar for getTry().hasException()
bool hasException();
/** A reference to the Try of the value */
Try<T>& getTry();
/// If the promise has been fulfilled, return an Optional with the Try<T>.
/// Otherwise return an empty Optional.
/// Note that this moves the Try<T> out.
......@@ -233,7 +230,6 @@ class SemiFuture : private futures::detail::FutureBase<T> {
/* implicit */ SemiFuture(Future<T>&&) noexcept;
using Base::cancel;
using Base::getTry;
using Base::hasException;
using Base::hasValue;
using Base::isActive;
......@@ -256,6 +252,10 @@ class SemiFuture : private futures::detail::FutureBase<T> {
/// exception).
T get(Duration dur) &&;
/// Block until the future is fulfilled, or until timed out. Returns the
/// Try of the value (moved out).
Try<T> getTry() &&;
/// Block until this Future is complete. Returns a reference to this Future.
SemiFuture<T>& wait() &;
......@@ -392,7 +392,6 @@ class Future : private futures::detail::FutureBase<T> {
Future& operator=(Future<T2>&&);
using Base::cancel;
using Base::getTry;
using Base::hasException;
using Base::hasValue;
using Base::isActive;
......@@ -646,6 +645,9 @@ class Future : private futures::detail::FutureBase<T> {
/// exception).
T get(Duration dur);
/** A reference to the Try of the value */
Try<T>& getTry();
/// Block until this Future is complete. Returns a reference to this Future.
Future<T>& wait() &;
......
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