From: Dave Watson Date: Thu, 28 May 2015 20:57:27 +0000 (-0700) Subject: Chain interrupt handlers X-Git-Tag: v0.42.0~20 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fa2487779f809c0283f16dc4fc081e9384beefa6;p=folly.git Chain interrupt handlers Summary: Chain interrupt handlers in then(). User can always choose to set a new one later. Test Plan: added unittest Reviewed By: hans@fb.com Subscribers: doug, folly-diffs@, jsedgwick, yfeldblum, chalfant FB internal diff: D2091569 Signature: t1:2091569:1432760579:ea7afa9b4e62e4b04b4d5f17950b9b7356a57f09 --- diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index d315b505..7d106912 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -116,6 +116,7 @@ Future::thenImplementation(F func, detail::argResult) { // wrap these so we can move them into the lambda folly::MoveWrapper> p; + p->setInterruptHandler(core_->getInterruptHandler()); folly::MoveWrapper funcm(std::forward(func)); // grab the Future now before we lose our handle on the Promise diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 3729b622..708d28a6 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -249,6 +249,11 @@ class Core { } } + std::function getInterruptHandler() { + folly::MSLGuard guard(interruptLock_); + return interruptHandler_; + } + /// Call only from Promise thread void setInterruptHandler(std::function fn) { folly::MSLGuard guard(interruptLock_); diff --git a/folly/futures/test/TimekeeperTest.cpp b/folly/futures/test/TimekeeperTest.cpp index 0fdac19a..badcc305 100644 --- a/folly/futures/test/TimekeeperTest.cpp +++ b/folly/futures/test/TimekeeperTest.cpp @@ -160,6 +160,15 @@ TEST(Timekeeper, interruptDoesntCrash) { f.cancel(); } +TEST(Timekeeper, chainedInterruptTest) { + bool test = false; + auto f = futures::sleep(Duration(100)).then([&](){ + test = true; + }); + f.cancel(); + f.wait(); + EXPECT_FALSE(test); +} // TODO(5921764) /* TEST(Timekeeper, onTimeoutPropagates) {