Commit fa248777 authored by Dave Watson's avatar Dave Watson Committed by Noam Lerner

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
parent f92ce30d
...@@ -116,6 +116,7 @@ Future<T>::thenImplementation(F func, detail::argResult<isTry, F, Args...>) { ...@@ -116,6 +116,7 @@ Future<T>::thenImplementation(F func, detail::argResult<isTry, F, Args...>) {
// wrap these so we can move them into the lambda // wrap these so we can move them into the lambda
folly::MoveWrapper<Promise<B>> p; folly::MoveWrapper<Promise<B>> p;
p->setInterruptHandler(core_->getInterruptHandler());
folly::MoveWrapper<F> funcm(std::forward<F>(func)); folly::MoveWrapper<F> funcm(std::forward<F>(func));
// grab the Future now before we lose our handle on the Promise // grab the Future now before we lose our handle on the Promise
......
...@@ -249,6 +249,11 @@ class Core { ...@@ -249,6 +249,11 @@ class Core {
} }
} }
std::function<void(exception_wrapper const&)> getInterruptHandler() {
folly::MSLGuard guard(interruptLock_);
return interruptHandler_;
}
/// Call only from Promise thread /// Call only from Promise thread
void setInterruptHandler(std::function<void(exception_wrapper const&)> fn) { void setInterruptHandler(std::function<void(exception_wrapper const&)> fn) {
folly::MSLGuard guard(interruptLock_); folly::MSLGuard guard(interruptLock_);
......
...@@ -160,6 +160,15 @@ TEST(Timekeeper, interruptDoesntCrash) { ...@@ -160,6 +160,15 @@ TEST(Timekeeper, interruptDoesntCrash) {
f.cancel(); 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) // TODO(5921764)
/* /*
TEST(Timekeeper, onTimeoutPropagates) { TEST(Timekeeper, onTimeoutPropagates) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment