Commit c1bd7145 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Future<typename>::getTryVia

Summary:
[Folly] `Future<typename>::getTryVia`.

We have `waitVia` and `getVia` and `getTry`, but `getTryVia` was missing.

Reviewed By: fugalh

Differential Revision: D4254972

fbshipit-source-id: 403e1a3496ad5dfc93c4c55ab75a83bcc89e6c64
parent 7c8f000f
......@@ -415,6 +415,11 @@ Try<T>& Future<T>::getTry() {
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;
......
......@@ -129,6 +129,11 @@ class Future {
/** 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.
......
......@@ -400,6 +400,32 @@ TEST(Via, getVia) {
}
}
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;
......
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