Commit 959e3cff authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Make blockingWait fibers compatible

Summary: This will make it easy to use coro primitives from fibers code.

Reviewed By: lewissbaker

Differential Revision: D9932012

fbshipit-source-id: cd0524ccfee7bee9405f29ddaa3533084b18b38b
parent 25612675
......@@ -17,6 +17,7 @@
#include <folly/Try.h>
#include <folly/experimental/coro/Traits.h>
#include <folly/fibers/Baton.h>
#include <folly/synchronization/Baton.h>
#include <cassert>
......@@ -64,7 +65,7 @@ class BlockingWaitPromiseBase {
}
private:
folly::Baton<> baton_;
folly::fibers::Baton baton_;
};
template <typename T>
......
......@@ -22,6 +22,8 @@
#include <folly/experimental/coro/Baton.h>
#include <folly/experimental/coro/BlockingWait.h>
#include <folly/experimental/coro/Utils.h>
#include <folly/fibers/FiberManager.h>
#include <folly/fibers/FiberManagerMap.h>
#include <folly/portability/GTest.h>
#include <memory>
......@@ -224,4 +226,22 @@ TEST(BlockingWait, moveCountingAwaitableReady) {
EXPECT_GE(4, result.count_);
}
TEST(BlockingWait, WaitInFiber) {
SimplePromise<int> promise;
folly::EventBase evb;
auto& fm = folly::fibers::getFiberManager(evb);
auto future =
fm.addTaskFuture([&] { return folly::coro::blockingWait(promise); });
evb.loopOnce();
EXPECT_FALSE(future.isReady());
promise.emplace(42);
evb.loopOnce();
EXPECT_TRUE(future.isReady());
EXPECT_EQ(42, std::move(future).get());
}
#endif
......@@ -34,7 +34,7 @@ class Baton::FiberWaiter : public Baton::Waiter {
Fiber* fiber_{nullptr};
};
inline Baton::Baton() : Baton(NO_WAITER) {
inline Baton::Baton() noexcept : Baton(NO_WAITER) {
assert(Baton(NO_WAITER).futex_.futex == static_cast<uint32_t>(NO_WAITER));
assert(Baton(POSTED).futex_.futex == static_cast<uint32_t>(POSTED));
assert(Baton(TIMEOUT).futex_.futex == static_cast<uint32_t>(TIMEOUT));
......
......@@ -48,9 +48,9 @@ class Baton {
virtual ~Waiter() {}
};
Baton();
Baton() noexcept;
~Baton() {}
~Baton() noexcept = default;
bool ready() const {
auto state = waiter_.load();
......
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