// Our Callback object for HHWheelTimer
struct WTCallback : public folly::HHWheelTimer::Callback {
// Only allow creation by this factory, to ensure heap allocation.
- static WTCallback* create() {
+ static WTCallback* create(EventBase* base) {
// optimization opportunity: memory pool
- return new WTCallback();
+ return new WTCallback(base);
}
Future<void> getFuture() {
}
protected:
+ EventBase* base_;
Promise<void> promise_;
- explicit WTCallback() {
+ explicit WTCallback(EventBase* base)
+ : base_(base) {
promise_.setInterruptHandler(
std::bind(&WTCallback::interruptHandler, this));
}
}
void interruptHandler() {
- cancelTimeout();
- delete this;
+ base_->runInEventBaseThread([=] {
+ cancelTimeout();
+ delete this;
+ });
}
};
}
Future<void> ThreadWheelTimekeeper::after(Duration dur) {
- auto cob = WTCallback::create();
+ auto cob = WTCallback::create(&eventBase_);
auto f = cob->getFuture();
eventBase_.runInEventBaseThread([=]{
wheelTimer_->scheduleTimeout(cob, dur);
std::chrono::milliseconds const one_ms(1);
std::chrono::milliseconds const awhile(10);
+std::chrono::seconds const too_long(10);
std::chrono::steady_clock::time_point now() {
return std::chrono::steady_clock::now();
// just testing compilation here
}
+TEST(Timekeeper, interruptDoesntCrash) {
+ auto f = futures::sleep(too_long);
+ f.cancel();
+}
+
// TODO(5921764)
/*
TEST(Timekeeper, onTimeoutPropagates) {