1
0
mirror of https://github.com/tearshark/librf.git synced 2024-10-04 08:50:31 +08:00

awaitable_t兼容老的future用法

完成相关范例
This commit is contained in:
tearshark 2020-02-16 12:14:25 +08:00
parent 2bd318d052
commit 39cd2f5dcf
5 changed files with 13 additions and 17 deletions

View File

@ -33,7 +33,7 @@ namespace resumef
{ {
return future_type{ _state }; return future_type{ _state };
} }
protected:
mutable counted_ptr<state_type> _state = make_counted<state_type>(true); mutable counted_ptr<state_type> _state = make_counted<state_type>(true);
}; };

View File

@ -82,6 +82,12 @@ namespace resumef
void set_exception(std::exception_ptr e); void set_exception(std::exception_ptr e);
template<class _Exp>
void throw_exception(_Exp e) const
{
set_exception(std::make_exception_ptr(std::move(e)));
}
template<class _PromiseT, typename = std::enable_if_t<is_promise_v<_PromiseT>>> template<class _PromiseT, typename = std::enable_if_t<is_promise_v<_PromiseT>>>
void future_await_suspend(coroutine_handle<_PromiseT> handler); void future_await_suspend(coroutine_handle<_PromiseT> handler);

View File

@ -15,7 +15,7 @@ auto async_heavy_computing_tasks(int64_t val)
{ {
using namespace std::chrono; using namespace std::chrono;
promise_t<int64_t> awaitable; awaitable_t<int64_t> awaitable;
std::thread([val, st = awaitable._state] std::thread([val, st = awaitable._state]
{ {

View File

@ -38,7 +38,9 @@ int main(int argc, const char* argv[])
//resumable_main_resumable(); //resumable_main_resumable();
//resumable_main_routine(); //resumable_main_routine();
//resumable_main_exception(); //resumable_main_exception();
resumable_main_dynamic_go(); //resumable_main_dynamic_go();
//resumable_main_multi_thread();
resumable_main_timer();
/* /*
resumable_main_benchmark_mem(); resumable_main_benchmark_mem();
@ -48,8 +50,6 @@ int main(int argc, const char* argv[])
resumable_main_benchmark_asio_server(); resumable_main_benchmark_asio_server();
resumable_main_when_all(); resumable_main_when_all();
resumable_main_multi_thread();
resumable_main_timer();
resumable_main_sleep(); resumable_main_sleep();
resumable_main_mutex(); resumable_main_mutex();
resumable_main_event(); resumable_main_event();

View File

@ -249,12 +249,7 @@
</ClCompile> </ClCompile>
<ClCompile Include="..\tutorial\test_async_exception.cpp" /> <ClCompile Include="..\tutorial\test_async_exception.cpp" />
<ClCompile Include="..\tutorial\test_async_modern_cb.cpp" /> <ClCompile Include="..\tutorial\test_async_modern_cb.cpp" />
<ClCompile Include="..\tutorial\test_async_multi_thread.cpp"> <ClCompile Include="..\tutorial\test_async_multi_thread.cpp" />
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\tutorial\test_async_mutex.cpp"> <ClCompile Include="..\tutorial\test_async_mutex.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@ -270,12 +265,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\tutorial\test_async_suspend_always.cpp" /> <ClCompile Include="..\tutorial\test_async_suspend_always.cpp" />
<ClCompile Include="..\tutorial\test_async_timer.cpp"> <ClCompile Include="..\tutorial\test_async_timer.cpp" />
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\tutorial\test_async_when_all.cpp"> <ClCompile Include="..\tutorial\test_async_when_all.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>