update
This commit is contained in:
parent
33f1554c47
commit
038c1170fd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/build
|
||||||
|
/.cache
|
15
CMakeLists.txt
Normal file
15
CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
project(ZtAsyncio CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 26
|
||||||
|
CMAKE_CXX_STANDARD_REQUIRED ON
|
||||||
|
CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(test1
|
||||||
|
src/test1.cpp
|
||||||
|
)
|
24
include/asyncio.hpp
Normal file
24
include/asyncio.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <coroutine>
|
||||||
|
#include <future>
|
||||||
|
namespace zt{
|
||||||
|
template<class T>
|
||||||
|
struct Task{
|
||||||
|
struct promise_type;
|
||||||
|
struct promise_type{
|
||||||
|
std::promise<T> promise_;
|
||||||
|
void return_value(T value){promise_.set_value(value);}
|
||||||
|
auto initial_suspend(){
|
||||||
|
return std::suspend_always{};
|
||||||
|
}
|
||||||
|
auto final_suspend()noexcept{
|
||||||
|
return std::suspend_always{};
|
||||||
|
}
|
||||||
|
auto get_return_object(){
|
||||||
|
return Task<T>{};
|
||||||
|
}
|
||||||
|
void unhandled_exception(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
15
src/test1.cpp
Normal file
15
src/test1.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <future>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <coroutine>
|
||||||
|
#include "asyncio.hpp"
|
||||||
|
|
||||||
|
zt::Task<int> return0(){
|
||||||
|
std::println(std::cout,"return 0;");
|
||||||
|
co_return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
auto ret = return0();
|
||||||
|
ret.promise_type
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user