Only consume the data when chaining continuations

This commit is contained in:
Denis Blank 2018-12-08 02:32:39 +01:00
parent d416698758
commit bcafd1b333

View File

@ -126,7 +126,7 @@ struct attorney {
typename T, typename A, typename T, typename A,
typename Continuable = continuable_base<std::decay_t<T>, std::decay_t<A>>> typename Continuable = continuable_base<std::decay_t<T>, std::decay_t<A>>>
static auto create_from(T&& continuation, A annotation, static auto create_from(T&& continuation, A annotation,
util::ownership ownership) { util::ownership ownership = {}) {
(void)annotation; (void)annotation;
return Continuable({std::forward<T>(continuation)}, ownership); return Continuable({std::forward<T>(continuation)}, ownership);
} }
@ -720,7 +720,7 @@ struct chained_continuation<traits::identity<Args...>, HandleResults,
// Invoke the continuation with a proxy callback. // Invoke the continuation with a proxy callback.
// The proxy callback is responsible for passing // The proxy callback is responsible for passing
// the result to the callback as well as decorating it. // the result to the callback as well as decorating it.
invoke_continuation(std::move(continuation_), std::move(proxy)); util::invoke(std::move(continuation_), std::move(proxy));
} }
bool operator()(is_ready_arg_t) const noexcept { bool operator()(is_ready_arg_t) const noexcept {
@ -755,19 +755,18 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback,
next_hint_of(std::integral_constant<handle_results, HandleResults>{}, next_hint_of(std::integral_constant<handle_results, HandleResults>{},
traits::identify<decltype(callback)>{}, Hint{}); traits::identify<decltype(callback)>{}, Hint{});
// TODO consume only the data here so the freeze isn't needed auto data =
auto ownership_ = attorney::ownership_of(continuation); attorney::consume(std::forward<Continuation>(continuation).finish());
continuation.freeze();
using continuation_t = chained_continuation< using continuation_t =
Hint, HandleResults, HandleErrors, traits::unrefcv_t<Continuation>, chained_continuation<Hint, HandleResults, HandleErrors, decltype(data),
traits::unrefcv_t<Callback>, traits::unrefcv_t<Executor>>; traits::unrefcv_t<Callback>,
traits::unrefcv_t<Executor>>;
return attorney::create_from( return attorney::create_from(continuation_t(std::move(data),
continuation_t(std::forward<Continuation>(continuation), std::forward<Callback>(callback),
std::forward<Callback>(callback), std::forward<Executor>(executor)),
std::forward<Executor>(executor)), next_hint);
next_hint, ownership_);
} }
/// Final invokes the given continuation chain: /// Final invokes the given continuation chain: