Summary: pulling the trigger
Test Plan: Unit tests. Wait for contbuild and dependent unit tests
Reviewed By: hannesr@fb.com
FB internal diff:
D1184842
when this returns true. */
bool isReady() const;
- /** Wait until the result (or exception) is ready. Once this returns,
- value() will not block, and isReady() will return true.
-
- XXX This implementation is simplistic and inefficient, but it does work
- and a fully intelligent implementation is coming down the pipe.
- */
- void wait() const {
- while (!isReady()) {
- // spin
- std::this_thread::yield();
- }
- }
-
Try<T>& valueTry();
/** When this Future has completed, execute func which is a function that
}
}
-TEST(Future, wait) {
- Promise<void> p;
- auto f = p.getFuture();
- auto t = std::thread([&] {
- std::this_thread::sleep_for(std::chrono::microseconds(10));
- p.setValue();
- });
-
- f.wait();
-
- EXPECT_TRUE(f.isReady());
-
- t.join();
-}
-
TEST(Future, whenAllVariadic) {
Promise<bool> pb;
Promise<int> pi;