mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 08:46:44 +08:00
Initial work on corooutine/await support
This commit is contained in:
parent
1c0c17f699
commit
26ff6312ed
@ -10,6 +10,7 @@ if (NOT DEFINED CONTINUABLE_UNIT_TESTS
|
||||
set(CONTINUABLE_UNIT_TESTS ON)
|
||||
endif()
|
||||
|
||||
include(cmake/CMakeLists.txt)
|
||||
add_subdirectory(dep)
|
||||
|
||||
# continuable-base
|
||||
@ -23,7 +24,8 @@ target_include_directories(continuable-base
|
||||
|
||||
target_link_libraries(continuable-base
|
||||
INTERFACE
|
||||
Threads::Threads)
|
||||
Threads::Threads
|
||||
continuable-coroutines)
|
||||
|
||||
target_compile_features(continuable-base
|
||||
INTERFACE
|
||||
@ -50,7 +52,7 @@ target_link_libraries(continuable
|
||||
function2)
|
||||
|
||||
# Create an install target
|
||||
install(TARGETS continuable-base continuable
|
||||
install(TARGETS continuable-coroutines continuable-base continuable
|
||||
EXPORT continuable-config
|
||||
INCLUDES DESTINATION include)
|
||||
|
||||
@ -92,8 +94,6 @@ if (CONTINUABLE_UNIT_TESTS)
|
||||
|
||||
enable_testing()
|
||||
|
||||
include(cmake/CMakeLists.txt)
|
||||
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(examples)
|
||||
add_subdirectory(test)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
add_library(continuable-features-flags INTERFACE)
|
||||
add_library(continuable-features-warnings INTERFACE)
|
||||
add_library(continuable-features-noexcept INTERFACE)
|
||||
add_library(continuable-coroutines INTERFACE)
|
||||
|
||||
include(cmake/configure_compiler.cmake)
|
||||
|
||||
@ -5,6 +5,16 @@ target_compile_options(continuable-features-warnings
|
||||
-pedantic
|
||||
-Wextra)
|
||||
|
||||
if (WITH_COROUTINES)
|
||||
target_compile_options(continuable-coroutines
|
||||
INTERFACE
|
||||
-fcoroutines-ts)
|
||||
|
||||
target_compile_definitions(continuable-coroutines
|
||||
INTERFACE
|
||||
-DCONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||
endif()
|
||||
|
||||
if (TESTS_NO_EXCEPTIONS)
|
||||
target_compile_options(continuable-features-noexcept
|
||||
INTERFACE
|
||||
@ -12,4 +22,3 @@ if (TESTS_NO_EXCEPTIONS)
|
||||
|
||||
message(STATUS "Clang: Disabled exceptions")
|
||||
endif()
|
||||
|
||||
|
||||
@ -19,11 +19,21 @@ target_compile_options(continuable-features-warnings
|
||||
INTERFACE
|
||||
/W4)
|
||||
|
||||
if (WITH_COROUTINES)
|
||||
target_compile_options(continuable-coroutines
|
||||
INTERFACE
|
||||
/await)
|
||||
|
||||
target_compile_definitions(continuable-coroutines
|
||||
INTERFACE
|
||||
-DCONTINUABLE_HAS_EXPERIMENTAL_COROUTINE)
|
||||
endif()
|
||||
|
||||
if (TESTS_NO_EXCEPTIONS)
|
||||
target_compile_definitions(continuable-features-noexcept
|
||||
INTERFACE
|
||||
-D_HAS_EXCEPTIONS=0)
|
||||
|
||||
|
||||
string(REGEX REPLACE "/GX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string(REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
message(STATUS "MSVC: Disabled exceptions")
|
||||
|
||||
@ -503,6 +503,22 @@ public:
|
||||
return std::move(*this);
|
||||
}
|
||||
|
||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
bool is_ready() const noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
void await_suspend(detail::types::coroutine_handle<> h) && {
|
||||
|
||||
h.resume();
|
||||
}
|
||||
|
||||
auto await_resume() {
|
||||
// if ec throw
|
||||
// return n;
|
||||
}
|
||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
|
||||
private:
|
||||
void release() noexcept {
|
||||
ownership_.release();
|
||||
|
||||
@ -52,4 +52,7 @@
|
||||
/// TODO Enable this
|
||||
#undef CONTINUABLE_HAS_CXX17_FOLD_EXPRESSION
|
||||
|
||||
/// This is enabled by the CMake project
|
||||
// #undef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
|
||||
#endif // CONTINUABLE_DETAIL_FEATURES_HPP_INCLUDED__
|
||||
|
||||
@ -39,6 +39,10 @@
|
||||
#endif // CONTINUABLE_WITH_NO_EXCEPTIONS
|
||||
#endif // CONTINUABLE_WITH_CUSTOM_ERROR_TYPE
|
||||
|
||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
#include <experimental/coroutine>
|
||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
|
||||
#include <continuable/continuable-api.hpp>
|
||||
#include <continuable/detail/features.hpp>
|
||||
|
||||
@ -62,6 +66,10 @@ using error_type = std::error_condition;
|
||||
struct this_thread_executor_tag {};
|
||||
/// A tag which is used to continue with an error
|
||||
struct dispatch_error_tag {};
|
||||
|
||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
using std::experimental::coroutine_handle;
|
||||
#endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
} // namespace types
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user