Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v.0.0.4 #4

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 169 additions & 51 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions concurrencpp/concurrencpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<ClInclude Include="src\platform_defs.h" />
<ClInclude Include="src\results\constants.h" />
<ClInclude Include="src\results\executor_exception.h" />
<ClInclude Include="src\results\make_result.h" />
<ClInclude Include="src\results\promises.h" />
<ClInclude Include="src\results\result_core.h" />
<ClInclude Include="src\results\result_fwd_declerations.h" />
Expand Down
3 changes: 3 additions & 0 deletions concurrencpp/concurrencpp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<ClInclude Include="src\results\constants.h">
<Filter>src\results</Filter>
</ClInclude>
<ClInclude Include="src\results\make_result.h">
<Filter>src\results</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\timers\timer.cpp">
Expand Down
1 change: 1 addition & 0 deletions concurrencpp/include/concurrencpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../src/timers/timer_queue.h"
#include "../src/runtime/runtime.h"
#include "../src/results/result.h"
#include "../src/results/make_result.h"
#include "../src/executors/executor_all.h"

#endif
40 changes: 40 additions & 0 deletions concurrencpp/src/results/make_result.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef CONCURRENCPP_MAKE_RESULT_H
#define CONCURRENCPP_MAKE_RESULT_H

#include "result.h"

namespace concurrencpp {
template<class type, class ... argument_types>
result<type> make_ready_result(argument_types&& ... arguments) {
static_assert(
std::is_constructible_v<type, argument_types...> || std::is_same_v<type, void>,
"concurrencpp::make_ready_result - <<type>> is not constructible from <<argument_types...>");

auto result_core_ptr = std::make_shared<details::result_core<type>>();
result_core_ptr->set_result(std::forward<argument_types>(arguments)...);
result_core_ptr->publish_result();
return { std::move(result_core_ptr) };
}

inline result<void> make_ready_result() {
auto result_core_ptr = std::make_shared<details::result_core<void>>();
result_core_ptr->set_result();
result_core_ptr->publish_result();
return { std::move(result_core_ptr) };
}

template<class type>
result<type> make_exceptional_result(std::exception_ptr exception_ptr) {
auto result_core_ptr = std::make_shared<details::result_core<type>>();
result_core_ptr->set_exception(exception_ptr);
result_core_ptr->publish_result();
return { std::move(result_core_ptr) };
}

template<class type, class exception_type>
result<type> make_exceptional_result(exception_type exception) {
return make_exceptional_result<type>(std::make_exception_ptr(exception));
}
}

#endif
19 changes: 0 additions & 19 deletions concurrencpp/src/results/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,6 @@ namespace concurrencpp {
return result<type>(m_state);
}
};

template<class type, class ... argument_types>
result<type> make_ready_result(argument_types&& ... arguments) {
result_promise<type> promise;
promise.set_result(std::forward<argument_types>(arguments)...);
return promise.get_result();
}

template<class type>
result<type> make_exceptional_result(std::exception_ptr exception_ptr) {
result_promise<type> promise;
promise.set_exception(exception_ptr);
return promise.get_result();
}

template<class type, class exception_type>
result<type> make_exceptional_result(exception_type exception) {
return make_exceptional_result(std::make_exception_ptr(exception));
}
}

#endif
5 changes: 4 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ add_executable(
tests/result_tests/result_await_tests.cpp
tests/result_tests/result_resolve_tests.cpp
tests/result_tests/result_promise_tests.cpp
tests/result_tests/coroutine_adapters_tests.cpp
tests/result_tests/make_result_tests.cpp

tests/coroutine_tests/coroutine_adapters_tests.cpp
tests/coroutine_tests/parallel_coroutines_tests.cpp
)
find_library(LIBRT rt)
if(LIBRT)
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@
<ClCompile Include="main.cpp" />
<ClCompile Include="tester\tester.cpp" />
<ClCompile Include="tests\all_tests.cpp" />
<ClCompile Include="tests\coroutine_tests\parallel_coroutines_tests.cpp" />
<ClCompile Include="tests\executor_tests\thread_pool_executor_tests.cpp" />
<ClCompile Include="tests\executor_tests\inline_executor_tests.cpp" />
<ClCompile Include="tests\executor_tests\manual_executor_tests.cpp" />
<ClCompile Include="tests\executor_tests\thread_executor_tests.cpp" />
<ClCompile Include="tests\executor_tests\worker_thread_executor_tests.cpp" />
<ClCompile Include="tests\result_tests\coroutine_adapters_tests.cpp" />
<ClCompile Include="tests\result_tests\make_result_tests.cpp" />
<ClCompile Include="tests\result_tests\result_await_tests.cpp" />
<ClCompile Include="tests\result_tests\result_promise_tests.cpp" />
<ClCompile Include="tests\result_tests\result_resolve_tests.cpp" />
Expand Down
15 changes: 12 additions & 3 deletions tests/tests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
<ClCompile Include="tests\result_tests\result_resolve_tests.cpp">
<Filter>tests\result_tests</Filter>
</ClCompile>
<ClCompile Include="tests\result_tests\coroutine_adapters_tests.cpp">
<Filter>tests\result_tests</Filter>
</ClCompile>
<ClCompile Include="tests\result_tests\result_await_tests.cpp">
<Filter>tests\result_tests</Filter>
</ClCompile>
Expand Down Expand Up @@ -50,6 +47,15 @@
<ClCompile Include="tests\runtime_tests.cpp">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="tests\result_tests\make_result_tests.cpp">
<Filter>tests\result_tests</Filter>
</ClCompile>
<ClCompile Include="tests\result_tests\coroutine_adapters_tests.cpp">
<Filter>tests\coroutine_tests</Filter>
</ClCompile>
<ClCompile Include="tests\coroutine_tests\parallel_coroutines_tests.cpp">
<Filter>tests\coroutine_tests</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="tester">
Expand All @@ -67,6 +73,9 @@
<Filter Include="tests\executor_tests">
<UniqueIdentifier>{f8cb7b88-65fd-4965-a4a3-bd6c2c47d345}</UniqueIdentifier>
</Filter>
<Filter Include="tests\coroutine_tests">
<UniqueIdentifier>{6293e16d-7a10-4fea-adcc-aea1122b86c7}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="tester\tester.h">
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/all_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ void concurrencpp::tests::test_all() {
test_result_resolve_all();
test_result_await_all();
test_result_promise();
test_make_result();

test_co_await();
test_parallel_coroutine();

test_timer();

Expand Down
15 changes: 9 additions & 6 deletions tests/tests/all_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
#define CONCURRENCPP_ALL_TESTS_H

namespace concurrencpp::tests {
void test_inline_executor();
void test_thread_pool_executor();
void test_thread_executor();
void test_worker_thread_executor();
void test_manual_executor();

void test_result_promise();
void test_result();
void test_result_resolve_all();
void test_result_await_all();
void test_result_await();
void test_co_await();
void test_make_result();

void test_inline_executor();
void test_thread_pool_executor();
void test_thread_executor();
void test_worker_thread_executor();
void test_manual_executor();
void test_co_await();
void test_parallel_coroutine();

void test_timer();

Expand Down
Loading