Chain interrupt handlers
authorDave Watson <davejwatson@fb.com>
Thu, 28 May 2015 20:57:27 +0000 (13:57 -0700)
committerNoam Lerner <noamler@fb.com>
Wed, 3 Jun 2015 16:47:54 +0000 (09:47 -0700)
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

folly/futures/Future-inl.h
folly/futures/detail/Core.h
folly/futures/test/TimekeeperTest.cpp

index d315b5055e46131e5c0a7675326b38e3da6e4c0f..7d106912f4f2727a9529f56a71631b83c258fe12 100644 (file)
@@ -116,6 +116,7 @@ Future<T>::thenImplementation(F func, detail::argResult<isTry, F, Args...>) {
 
   // wrap these so we can move them into the lambda
   folly::MoveWrapper<Promise<B>> p;
+  p->setInterruptHandler(core_->getInterruptHandler());
   folly::MoveWrapper<F> funcm(std::forward<F>(func));
 
   // grab the Future now before we lose our handle on the Promise
index 3729b622d75e73c4b9ac83b1a59ff14523c8d723..708d28a606130f73644e3de772a4805a6f5f6f05 100644 (file)
@@ -249,6 +249,11 @@ class Core {
     }
   }
 
+  std::function<void(exception_wrapper const&)> getInterruptHandler() {
+    folly::MSLGuard guard(interruptLock_);
+    return interruptHandler_;
+  }
+
   /// Call only from Promise thread
   void setInterruptHandler(std::function<void(exception_wrapper const&)> fn) {
     folly::MSLGuard guard(interruptLock_);
index 0fdac19a638eb326f7d556990e574fb4971d955e..badcc305db0c0eca45a2b5abe7458c1cfe4cc9e5 100644 (file)
@@ -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) {