File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change 1919world
2020```
2121
22+ ## Dump callstack
23+ ``` cpp
24+ Task<int > factorial (int n) {
25+ if (n <= 1) {
26+ co_await dump_callstack();
27+ co_return 1;
28+ }
29+ co_return (co_await factorial(n - 1)) * n;
30+ }
31+
32+ int main() {
33+ fmt::print("run result: {}\n", asyncio::run(factorial(10)));
34+ return 0;
35+ }
36+ ```
37+ output:
38+ ```shell
39+ [0] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:17
40+ [1] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
41+ [2] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
42+ [3] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
43+ [4] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
44+ [5] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
45+ [6] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
46+ [7] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
47+ [8] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
48+ [9] void factorial(factorial(int)::_Z9factoriali.Frame*) at /project/asyncio/test/st/hello_world.cpp:20
49+
50+ run result: 3628800
51+ ```
52+
2253## Gather
2354``` cpp
2455auto factorial (std::string_view name, int number) -> Task<int > {
@@ -75,4 +106,4 @@ Task C: factorial(4) = 24
75106
76107## Reference
77108- https://github.com/lewissbaker/cppcoro
78- - https://docs.python.org/3/library/asyncio.html
109+ - https://docs.python.org/3/library/asyncio.html
You can’t perform that action at this time.
0 commit comments