add nf7::Future::Chain() method

This commit is contained in:
falsycat 2022-10-12 10:25:10 +09:00
parent 4b79c5e4df
commit 7ee770e67d

View File

@ -290,6 +290,17 @@ class Future final {
return Catch<E>(nullptr, std::move(f));
}
// Finalizes the other promise on finalize of this future.
ThisFuture& Chain(auto& pro, auto&& func) noexcept {
return Then([pro, func = std::move(func)](auto& fu) mutable {
try {
pro.Return(func(fu.value()));
} catch (...) {
pro.Throw(std::current_exception());
}
});
}
const auto& value() const {
if (imm_) {
if (std::holds_alternative<T>(*imm_)) return std::get<T>(*imm_);