feat update
This commit is contained in:
parent
bd0f7bd208
commit
2bb58ab55a
@ -32,7 +32,11 @@ if (SLED_LOCATION_PATH)
|
|||||||
target_compile_definitions(sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
|
target_compile_definitions(sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
|
||||||
endif()
|
endif()
|
||||||
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
# 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(
|
target_sources(
|
||||||
sled
|
sled
|
||||||
PRIVATE
|
PRIVATE
|
||||||
@ -95,6 +99,7 @@ if(SLED_BUILD_TESTS)
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(googletest)
|
FetchContent_MakeAvailable(googletest)
|
||||||
add_executable(sled_tests
|
add_executable(sled_tests
|
||||||
|
src/exec/just_test.cc
|
||||||
src/any_test.cc
|
src/any_test.cc
|
||||||
src/filesystem/path_test.cc
|
src/filesystem/path_test.cc
|
||||||
src/strings/base64_test.cc
|
src/strings/base64_test.cc
|
||||||
|
68
include/sled/exec/just.h
Normal file
68
include/sled/exec/just.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef SLED_EXEC_JUST_H
|
||||||
|
#define SLED_EXEC_JUST_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace sled {
|
||||||
|
|
||||||
|
struct immovable {
|
||||||
|
immovable() = default;
|
||||||
|
immovable(immovable &&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename S, typename R>
|
||||||
|
using connect_result_t = decltype(connect(std::declval<S>(), std::declval<R>()));
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using sender_result_t = typename T::result_t;
|
||||||
|
|
||||||
|
template<typename R, typename T>
|
||||||
|
struct just_operation : immovable {
|
||||||
|
R receiver;
|
||||||
|
T value;
|
||||||
|
|
||||||
|
friend void start(just_operation &self) { set_value(self.receiver, self.value); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct just_sender {
|
||||||
|
using result_t = T;
|
||||||
|
T value;
|
||||||
|
|
||||||
|
template<typename R>
|
||||||
|
just_operation<R, T> connect(R receiver)
|
||||||
|
{
|
||||||
|
return {{}, receiver, this->value};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
just_sender<T>
|
||||||
|
just(T t)
|
||||||
|
{
|
||||||
|
return {t};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cout_receiver {
|
||||||
|
template<typename T>
|
||||||
|
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
|
9
src/exec/just_test.cc
Normal file
9
src/exec/just_test.cc
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "sled/ref_count.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <sled/exec/just.h>
|
||||||
|
|
||||||
|
TEST(just, basic)
|
||||||
|
{
|
||||||
|
sled::just_sender<int> sender = sled::just(1);
|
||||||
|
auto op = connect(sender, sled::cout_receiver{});
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
#include "schedulers/rx-currentthread.hpp"
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <sled/rx.h>
|
#include <sled/rx.h>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user