return core_->getTry();
}
+template <class T>
+Try<T>& Future<T>::getTryVia(DrivableExecutor* e) {
+ return waitVia(e).getTry();
+}
+
template <class T>
Optional<Try<T>> Future<T>::poll() {
Optional<Try<T>> o;
/** A reference to the Try of the value */
Try<T>& getTry();
+ /// Call e->drive() repeatedly until the future is fulfilled. Examples
+ /// of DrivableExecutor include EventBase and ManualExecutor. Returns a
+ /// reference to the Try of the value.
+ Try<T>& getTryVia(DrivableExecutor* e);
+
/// 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.
}
}
+TEST(Via, getTryVia) {
+ {
+ // non-void
+ ManualExecutor x;
+ auto f = via(&x).then([] { return 23; });
+ EXPECT_FALSE(f.isReady());
+ EXPECT_EQ(23, f.getTryVia(&x).value());
+ }
+
+ {
+ // void
+ ManualExecutor x;
+ auto f = via(&x).then();
+ EXPECT_FALSE(f.isReady());
+ auto t = f.getTryVia(&x);
+ EXPECT_TRUE(t.hasValue());
+ }
+
+ {
+ DummyDrivableExecutor x;
+ auto f = makeFuture(23);
+ EXPECT_EQ(23, f.getTryVia(&x).value());
+ EXPECT_FALSE(x.ran);
+ }
+}
+
TEST(Via, waitVia) {
{
ManualExecutor x;