Browse Source

awaitable_t兼容老的future用法

完成相关范例
tags/v2.9.7
tearshark 4 years ago
parent
commit
39cd2f5dcf
5 changed files with 13 additions and 17 deletions
  1. 1
    1
      librf/src/awaitable.h
  2. 6
    0
      librf/src/state.h
  3. 1
    1
      tutorial/test_async_multi_thread.cpp
  4. 3
    3
      vs_proj/librf.cpp
  5. 2
    12
      vs_proj/librf.vcxproj

+ 1
- 1
librf/src/awaitable.h View File

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


+ 6
- 0
librf/src/state.h View File

@@ -82,6 +82,12 @@ namespace resumef
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>>>
void future_await_suspend(coroutine_handle<_PromiseT> handler);

+ 1
- 1
tutorial/test_async_multi_thread.cpp View File

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

+ 3
- 3
vs_proj/librf.cpp View File

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

+ 2
- 12
vs_proj/librf.vcxproj View File

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

Loading…
Cancel
Save