#pragma once
#include <atomic>
#include <folly/Portability.h>
#include <folly/detail/Futex.h>
#include <folly/experimental/coro/Coroutine.h>
#include <folly/io/async/HHWheelTimer.h>
namespace folly {
namespace fibers {
class Fiber;
class FiberManager;
class Baton { … };
#if FOLLY_HAS_COROUTINES
namespace detail {
class BatonAwaitableWaiter : public Baton::Waiter {
public:
explicit BatonAwaitableWaiter(Baton& baton) : baton_(baton) {}
void post() override {
assert(h_);
h_();
}
bool await_ready() const { return baton_.ready(); }
void await_resume() {}
void await_suspend(coro::coroutine_handle<> h) {
assert(!h_);
h_ = std::move(h);
baton_.setWaiter(*this);
}
private:
coro::coroutine_handle<> h_;
Baton& baton_;
};
}
inline detail::BatonAwaitableWaiter operator co_await(
Baton & baton) {
return detail::BatonAwaitableWaiter(baton);
}
#endif
}
}
#include <folly/fibers/Baton-inl.h>