Commit 7c9d20fd authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

Future::get() - make postcond testable by callers

Summary:
SemiFuture::get() & Future::get() both render the `this` object in a consumed / moved-out state. However Future::get()'s postcondition was untestable by callers - it consumed the value within the core but left `this->valid()` true.

Goal: make Future::get():
- function like SemiFuture::get()
- testable by callers (see `valid()`)

Reviewed By: yfeldblum

Differential Revision: D7840699

fbshipit-source-id: 5102e9c3de026c021bf322b5109aafcc115207a2
parent afb57872
...@@ -1891,7 +1891,8 @@ Future<T>&& Future<T>::waitVia(TimedDrivableExecutor* e, Duration dur) && { ...@@ -1891,7 +1891,8 @@ Future<T>&& Future<T>::waitVia(TimedDrivableExecutor* e, Duration dur) && {
template <class T> template <class T>
T Future<T>::get() { T Future<T>::get() {
return std::move(wait().value()); wait();
return copy(std::move(*this)).value();
} }
template <class T> template <class T>
...@@ -1900,7 +1901,7 @@ T Future<T>::get(Duration dur) { ...@@ -1900,7 +1901,7 @@ T Future<T>::get(Duration dur) {
if (!this->isReady()) { if (!this->isReady()) {
throwTimedOut(); throwTimedOut();
} }
return std::move(this->value()); return copy(std::move(*this)).value();
} }
template <class T> template <class T>
......
...@@ -223,7 +223,6 @@ TEST(Future, hasPostconditionValid) { ...@@ -223,7 +223,6 @@ TEST(Future, hasPostconditionValid) {
DOIT(swallow(f.poll())); DOIT(swallow(f.poll()));
DOIT(f.raise(std::logic_error("foo"))); DOIT(f.raise(std::logic_error("foo")));
DOIT(f.cancel()); DOIT(f.cancel());
DOIT(swallow(f.get()));
DOIT(swallow(f.getTry())); DOIT(swallow(f.getTry()));
DOIT(f.wait()); DOIT(f.wait());
DOIT(std::move(f.wait())); DOIT(std::move(f.wait()));
...@@ -278,6 +277,8 @@ TEST(Future, hasPostconditionInvalid) { ...@@ -278,6 +277,8 @@ TEST(Future, hasPostconditionInvalid) {
DOIT(makeValid(), swallow(std::move(f).wait())); DOIT(makeValid(), swallow(std::move(f).wait()));
DOIT(makeValid(), swallow(std::move(f.wait()))); DOIT(makeValid(), swallow(std::move(f.wait())));
DOIT(makeValid(), swallow(f.semi())); DOIT(makeValid(), swallow(f.semi()));
DOIT(makeValid(), swallow(f.get()));
DOIT(makeValid(), std::move(f).get());
#undef DOIT #undef DOIT
} }
......
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