From 5b6406296f4de1ed198531c7a95ac78c6ba7fc4f Mon Sep 17 00:00:00 2001 From: Lee Howes Date: Wed, 27 Dec 2017 12:54:44 -0800 Subject: [PATCH] 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 --- folly/futures/Future-inl.h | 24 +++++++++++++++--------- folly/futures/Future.h | 12 +++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 70b0f892..c7c66b58 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -208,12 +208,12 @@ bool FutureBase::isReady() const { template bool FutureBase::hasValue() { - return getTry().hasValue(); + return core_->getTry().hasValue(); } template bool FutureBase::hasException() { - return getTry().hasException(); + return core_->getTry().hasException(); } template @@ -224,13 +224,6 @@ void FutureBase::detach() { } } -template -Try& FutureBase::getTry() { - throwIfInvalid(); - - return core_->getTry(); -} - template void FutureBase::throwIfInvalid() const { if (!core_) { @@ -1441,6 +1434,12 @@ T SemiFuture::get(Duration dur) && { } } +template +Try SemiFuture::getTry() && { + wait(); + return std::move(this->core_->getTry()); +} + template Future& Future::wait() & { futures::detail::waitImpl(*this); @@ -1492,6 +1491,13 @@ T Future::get(Duration dur) { } } +template +Try& Future::getTry() { + throwIfInvalid(); + + return this->core_->getTry(); +} + template T Future::getVia(DrivableExecutor* e) { return std::move(waitVia(e).value()); diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 2179623b..20a56b7e 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -106,9 +106,6 @@ class FutureBase { /// sugar for getTry().hasException() bool hasException(); - /** A reference to the Try of the value */ - Try& getTry(); - /// If the promise has been fulfilled, return an Optional with the Try. /// Otherwise return an empty Optional. /// Note that this moves the Try out. @@ -233,7 +230,6 @@ class SemiFuture : private futures::detail::FutureBase { /* implicit */ SemiFuture(Future&&) 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 { /// exception). T get(Duration dur) &&; + /// Block until the future is fulfilled, or until timed out. Returns the + /// Try of the value (moved out). + Try getTry() &&; + /// Block until this Future is complete. Returns a reference to this Future. SemiFuture& wait() &; @@ -392,7 +392,6 @@ class Future : private futures::detail::FutureBase { Future& operator=(Future&&); 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 { /// exception). T get(Duration dur); + /** A reference to the Try of the value */ + Try& getTry(); + /// Block until this Future is complete. Returns a reference to this Future. Future& wait() &; -- 2.34.1