From c3c914828a4db958893aaf307cc79d9aaf970431 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 15 Mar 2024 13:11:51 +0100 Subject: async, io: Fixing async tests for io --- modules/async/c++/async.hpp | 9 ++++++--- modules/async/c++/async.tmpl.hpp | 30 ++++++++++++++++++++++++------ modules/io/examples/echo_server.cpp | 3 ++- 3 files changed, 32 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/async/c++/async.hpp b/modules/async/c++/async.hpp index 257fbd7..b56742c 100644 --- a/modules/async/c++/async.hpp +++ b/modules/async/c++/async.hpp @@ -166,10 +166,12 @@ public: error operator()(error &&err); }; +/** + * Helper object holding a sink_conveyor_node + */ class conveyor_sink { private: own node_; - public: conveyor_sink(); conveyor_sink(own &&node); @@ -246,7 +248,7 @@ public: [[nodiscard]] conveyor limit(size_t val = 1); /** - * + * @todo implement */ [[nodiscard]] std::pair, merge_conveyor> merge(); @@ -257,9 +259,10 @@ public: */ template void detach(ErrorFunc &&err_func = propagate_error()); + /** * Creates a local sink which drops elements, but lifetime control remains - * in your hand. + * in your hand contrary to detach(). */ template [[nodiscard]] conveyor_sink diff --git a/modules/async/c++/async.tmpl.hpp b/modules/async/c++/async.tmpl.hpp index ba2a0b3..98573b5 100644 --- a/modules/async/c++/async.tmpl.hpp +++ b/modules/async/c++/async.tmpl.hpp @@ -106,14 +106,28 @@ std::pair, merge_conveyor> conveyor::merge() { std::move(node_ref)); } -template <> +/** + * + */ +template template -conveyor_sink conveyor::sink(ErrorFunc &&error_func) { - conveyor_storage *storage = node_->next_storage(); +conveyor_sink conveyor::sink(ErrorFunc &&error_func) { + conveyor conv_then = [&,this](){ + if constexpr (std::is_same_v ){ + return then([](){}, std::move(error_func)); + }else{ + return then([](T&&){}, std::move(error_func)); + } + }(); + auto nas = conveyor::from_conveyor(std::move(conv_then)); + assert(nas); + + conveyor_storage *storage = nas->next_storage(); + SAW_ASSERT(storage) { return conveyor_sink{}; } own sink_node = - heap(std::move(node_)); + heap(std::move(nas)); conveyor_storage *storage_ptr = static_cast(sink_node.get()); @@ -287,11 +301,15 @@ template void immediate_conveyor_node::parent_has_fired() { arm_next(); } } - +} +#include +namespace saw { template void immediate_conveyor_node::fire() { - + std::cout<<"Immediate fire"<space()<child_has_fired(); + std::cout<<"Immediate parent2: "<space()< 0 && parent_->space() > 0) { arm_last(); } diff --git a/modules/io/examples/echo_server.cpp b/modules/io/examples/echo_server.cpp index 24bdfa2..a158368 100644 --- a/modules/io/examples/echo_server.cpp +++ b/modules/io/examples/echo_server.cpp @@ -84,8 +84,9 @@ int main(){ std::cout<<"Entering waiting loop"<