25 Singleton<ThreadWheelTimekeeper> timekeeperSingleton_;
28 struct WTCallback :
public std::enable_shared_from_this<WTCallback>,
30 struct PrivateConstructorTag {};
33 WTCallback(PrivateConstructorTag, EventBase* base) :
base_(base) {}
36 static std::shared_ptr<WTCallback> create(EventBase* base) {
38 auto cob = std::make_shared<WTCallback>(PrivateConstructorTag{}, base);
42 cob->promise_.setInterruptHandler(
43 [cob](exception_wrapper ew) { cob->interruptHandler(
std::move(ew)); });
47 Future<Unit> getFuture() {
62 void timeoutExpired()
noexcept override {
65 auto promise = stealPromise();
66 if (!promise.isFulfilled()) {
71 void callbackCanceled()
noexcept override {
74 auto promise = stealPromise();
75 if (!promise.isFulfilled()) {
76 promise.setException(FutureNoTimekeeper{});
80 void interruptHandler(exception_wrapper ew) {
81 auto rBase = base_.rlock();
90 (*rBase)->runInEventBaseThread(
91 [me = shared_from_this(), ew =
std::move(ew)]()
mutable {
94 auto promise = me->stealPromise();
95 if (!promise.isFulfilled()) {
125 auto f = cob->getFuture();
141 [
this, cob, dur] { wheelTimer_->scheduleTimeout(cob.get(), dur); })) {
149 auto promise = cob->stealPromise();
150 if (!promise.isFulfilled()) {
160 return timekeeperSingleton_.try_get();
std::shared_ptr< Timekeeper > getTimekeeperSingleton()
bool runInEventBaseThreadAndWait(void(*fn)(T *), T *arg)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
ThreadWheelTimekeeper()
But it doesn't have to be a singleton.
std::chrono::milliseconds Duration
static UniquePtr newTimer(Args &&...args)
folly::Synchronized< EventBase * > base_
bool runInEventBaseThread(void(*fn)(T *), T *arg)
folly::EventBase eventBase_
void setName(const std::string &name)
~ThreadWheelTimekeeper() override
Future< Unit > after(Duration) override
HHWheelTimer::UniquePtr wheelTimer_