Commit 54f83501 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Propagate interrupt handler through wait with duration

Summary: Earlier change to duration waiting broke propagation of the interrupt handler. This change correctly propagates it into the new future that is returned.

Reviewed By: yfeldblum

Differential Revision: D17061618

fbshipit-source-id: b228221acbfab3ae94118c1197a485e01aa2e41e
parent 30f883ea
......@@ -2135,7 +2135,9 @@ template <class T>
Future<T> convertFuture(SemiFuture<T>&& sf, const Future<T>& f) {
// Carry executor from f, inserting an inline executor if it did not have one
auto* exe = f.getExecutor();
return std::move(sf).via(exe ? exe : &InlineExecutor::instance());
auto newFut = std::move(sf).via(exe ? exe : &InlineExecutor::instance());
newFut.core_->setInterruptHandlerNoLock(f.core_->getInterruptHandler());
return newFut;
}
template <class T>
......
......@@ -426,3 +426,16 @@ TEST(Wait, WaitPlusThen) {
t.join();
}
}
TEST(Wait, cancelAfterWait) {
folly::TestExecutor executor(1);
Promise<folly::Unit> p;
p.setInterruptHandler([&](const exception_wrapper& e) {
EXPECT_THROW(e.throw_exception(), FutureCancellation);
});
auto fut = p.getSemiFuture().within(std::chrono::seconds(1)).via(&executor);
fut.wait(std::chrono::milliseconds(1));
fut.cancel();
fut.wait();
}
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