std::swap(size_, other.size_);
std::swap(hasValue_, other.hasValue_);
std::swap(try_, other.try_);
+ std::swap(interruptHandler_, other.interruptHandler_);
std::swap(promises_, other.promises_);
return *this;
return makeFuture<T>(Try<T>(try_));
} else {
promises_.emplace_back();
+ if (interruptHandler_) {
+ promises_.back().setInterruptHandler(interruptHandler_);
+ }
return promises_.back().getFuture();
}
}
if (hasValue_) {
return;
}
+ interruptHandler_ = fn;
for (auto& p : promises_) {
p.setInterruptHandler(fn);
}
p = std::move(p2);
EXPECT_TRUE(p.isFulfilled());
}
+
+TEST(SharedPromise, interruptHandler) {
+ SharedPromise<int> p;
+ bool flag = false;
+ p.setInterruptHandler([&](const exception_wrapper&) { flag = true; });
+ auto f = p.getFuture();
+ f.cancel();
+ EXPECT_TRUE(flag);
+}