Skip to content

Instantly share code, notes, and snippets.

@Jackarain
Last active December 17, 2024 15:56
Show Gist options
  • Save Jackarain/67c787a8eec214e5a06bc27ddf304ef8 to your computer and use it in GitHub Desktop.
Save Jackarain/67c787a8eec214e5a06bc27ddf304ef8 to your computer and use it in GitHub Desktop.
async_simple 的爆栈问题测试代码
#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