mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 09:16:46 +08:00
Fix an issue when connecting void continuables
This commit is contained in:
parent
663779f083
commit
a1ee771059
@ -800,15 +800,15 @@ constexpr auto make_ready_continuable(FirstResult&& first_result,
|
|||||||
/// Returns a continuable with the parameterized result which instantly
|
/// Returns a continuable with the parameterized result which instantly
|
||||||
/// resolves the promise with the given error type.
|
/// resolves the promise with the given error type.
|
||||||
///
|
///
|
||||||
/// \tparam FirstArg The first result of the fake signature of the
|
/// \tparam Signature The fake signature of the returned continuable.
|
||||||
/// returned continuable.
|
|
||||||
/// \tparam Rest The rest of the result of the fake signature of the
|
|
||||||
/// returned continuable.
|
|
||||||
///
|
///
|
||||||
/// \since 3.0.0
|
/// \since 3.0.0
|
||||||
template <typename Exception, typename FirstArg = void, typename... Rest>
|
template <typename... Signature, typename Exception>
|
||||||
constexpr auto make_exceptional_continuable(Exception&& exception) {
|
constexpr auto make_exceptional_continuable(Exception&& exception) {
|
||||||
return make_continuable<FirstArg, Rest...>( // ...
|
static_assert(sizeof...(Signature) > 0,
|
||||||
|
"Requires at least one type for the fake signature!");
|
||||||
|
|
||||||
|
return make_continuable<Signature...>( // ...
|
||||||
[exception = std::forward<Exception>(exception)](auto&& promise) mutable {
|
[exception = std::forward<Exception>(exception)](auto&& promise) mutable {
|
||||||
std::forward<decltype(promise)>(promise).set_exception(
|
std::forward<decltype(promise)>(promise).set_exception(
|
||||||
std::move(exception));
|
std::move(exception));
|
||||||
|
|||||||
@ -77,10 +77,10 @@ auto when_all(Continuables&&... continuables) {
|
|||||||
/// std::vector<cti::continuable<int>>{cti::make_ready_continuable(3),
|
/// std::vector<cti::continuable<int>>{cti::make_ready_continuable(3),
|
||||||
/// cti::make_ready_continuable(4)},
|
/// cti::make_ready_continuable(4)},
|
||||||
/// std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
/// std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
||||||
/// .then([](int r0, int r1, int r2, std::vector<int> r34,
|
/// .then([](int r0, int r1, int r2, std::vector<int> r34,
|
||||||
/// std::tuple<std::tuple<int>> r5) {
|
/// std::tuple<std::tuple<int>> r5) {
|
||||||
/// // ...
|
/// // ...
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// \see continuable_base::operator>> for details.
|
/// \see continuable_base::operator>> for details.
|
||||||
|
|||||||
@ -182,18 +182,33 @@ public:
|
|||||||
// Continue the asynchronous sequential traversal
|
// Continue the asynchronous sequential traversal
|
||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
|
.fail([me = this->shared_from_this()](types::error_type exception) {
|
||||||
|
// Abort the traversal when an error occurred
|
||||||
|
std::move(me->data_.callback)(types::dispatch_error_tag{},
|
||||||
|
std::move(exception));
|
||||||
|
})
|
||||||
.done();
|
.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void finalize(traits::identity<void>) {
|
||||||
|
std::move(data_.callback)();
|
||||||
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void operator()(async_traverse_complete_tag, T&& /*pack*/) {
|
void finalize(traits::identity<T>) {
|
||||||
// Remove void result guard tags
|
|
||||||
auto cleaned =
|
auto cleaned =
|
||||||
map_pack(remapping::unpack_result_guards{}, std::move(data_.result));
|
map_pack(remapping::unpack_result_guards{}, std::move(data_.result));
|
||||||
|
|
||||||
// Call the final callback with the cleaned result
|
// Call the final callback with the cleaned result
|
||||||
traits::unpack(std::move(cleaned), std::move(data_.callback));
|
traits::unpack(std::move(cleaned), std::move(data_.callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void operator()(async_traverse_complete_tag, T&& /*pack*/) {
|
||||||
|
// Guard the final result against void
|
||||||
|
using result_t = decltype(
|
||||||
|
map_pack(remapping::unpack_result_guards{}, std::move(data_.result)));
|
||||||
|
finalize(traits::identity<result_t>{});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace seq
|
} // namespace seq
|
||||||
|
|
||||||
|
|||||||
@ -143,11 +143,30 @@ int main(int, char**) {
|
|||||||
util::unused(o2);
|
util::unused(o2);
|
||||||
});
|
});
|
||||||
|
|
||||||
cti::when_seq()
|
cti::when_seq(cti::make_ready_continuable()) // ...
|
||||||
.then([] {
|
.then([] {
|
||||||
// ...
|
// ...
|
||||||
})
|
});
|
||||||
|
|
||||||
|
cti::when_seq() // ...
|
||||||
|
.then([] {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
cti::when_seq(cti::make_exceptional_continuable<void>(std::error_condition{}))
|
||||||
.fail([](auto) {
|
.fail([](auto) {
|
||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*composition::apply_composition(
|
||||||
|
composition::composition_strategy_all_tag{},
|
||||||
|
cti::make_ready_continuable(0, 1), 2, //< See this plain value
|
||||||
|
std::vector<cti::continuable<int>>{cti::make_ready_continuable(3),
|
||||||
|
cti::make_ready_continuable(4)},
|
||||||
|
std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
||||||
|
.then([](int r0, int r1, int r2, std::vector<int> r34,
|
||||||
|
std::tuple<std::tuple<int>> r5) {
|
||||||
|
// ...
|
||||||
|
util::unused(r0, r1, r2, r34, r5);
|
||||||
|
});*/
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user