diff --git a/CMakeLists.txt b/CMakeLists.txt index 2971c7e..f1abe0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,11 @@ if (SLED_LOCATION_PATH) target_compile_definitions(sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}") endif() # add_subdirectory(3party/eigen EXCLUDE_FROM_ALL) -target_include_directories(sled PUBLIC 3party/eigen 3party/inja 3party/rxcpp) +target_include_directories(sled PUBLIC + include + 3party/eigen + 3party/inja + 3party/rxcpp) target_sources( sled PRIVATE @@ -95,6 +99,7 @@ if(SLED_BUILD_TESTS) ) FetchContent_MakeAvailable(googletest) add_executable(sled_tests + src/exec/just_test.cc src/any_test.cc src/filesystem/path_test.cc src/strings/base64_test.cc diff --git a/include/sled/exec/just.h b/include/sled/exec/just.h new file mode 100644 index 0000000..9b59521 --- /dev/null +++ b/include/sled/exec/just.h @@ -0,0 +1,68 @@ +#pragma once +#ifndef SLED_EXEC_JUST_H +#define SLED_EXEC_JUST_H + +#include +#include + +namespace sled { + +struct immovable { + immovable() = default; + immovable(immovable &&) = delete; +}; + +template +using connect_result_t = decltype(connect(std::declval(), std::declval())); + +template +using sender_result_t = typename T::result_t; + +template +struct just_operation : immovable { + R receiver; + T value; + + friend void start(just_operation &self) { set_value(self.receiver, self.value); } +}; + +template +struct just_sender { + using result_t = T; + T value; + + template + just_operation connect(R receiver) + { + return {{}, receiver, this->value}; + } +}; + +template +just_sender +just(T t) +{ + return {t}; +} + +struct cout_receiver { + template + friend void set_value(cout_receiver self, T &&val) + { + std::cout << "Result: " << val << std::endl; + } + + friend void set_error(cout_receiver self, std::exception_ptr e) + { + try { + std::rethrow_exception(e); + } catch (const std::exception &e) { + std::cout << "Error: " << e.what() << std::endl; + } + } + + friend void set_stopped(cout_receiver self) { std::cout << "Stopped" << std::endl; } +}; + +}// namespace sled +#endif// SLED_EXEC_JUST_H diff --git a/src/exec/just_test.cc b/src/exec/just_test.cc new file mode 100644 index 0000000..31f7a9a --- /dev/null +++ b/src/exec/just_test.cc @@ -0,0 +1,9 @@ +#include "sled/ref_count.h" +#include +#include + +TEST(just, basic) +{ + sled::just_sender sender = sled::just(1); + auto op = connect(sender, sled::cout_receiver{}); +} diff --git a/src/rx_test.cc b/src/rx_test.cc index bbf8295..ad583da 100644 --- a/src/rx_test.cc +++ b/src/rx_test.cc @@ -1,4 +1,3 @@ -#include "schedulers/rx-currentthread.hpp" #include #include