Last active
December 17, 2024 15:56
-
-
Save Jackarain/67c787a8eec214e5a06bc27ddf304ef8 to your computer and use it in GitHub Desktop.
async_simple 的爆栈问题测试代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include "async_simple/coro/Lazy.h" | |
#include "async_simple/coro/SyncAwait.h" | |
// asio_coro_util.hpp 在 demo_example 下, 这里仅仅为了调用 AsioCallbackAwaiter 这个简单的 Awaiter 而已. | |
#include "asio_coro_util.hpp" | |
Lazy<int> async_compute(int i) noexcept { | |
co_return co_await AsioCallbackAwaiter<int>{ | |
[&,i](std::coroutine_handle<> handle, auto set_resume_value) { | |
set_resume_value(i * 100); | |
handle.resume(); | |
}}; | |
} | |
Lazy<int> coro_compute() { | |
int sum = 0; | |
for (auto i = 0; i < 1000; i++) | |
sum += co_await async_compute(i); | |
std::cout << sum << std::endl; | |
co_return 0; | |
} | |
int main() { | |
syncAwait(coro_compute()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment