Skip to content

Commit d7014b9

Browse files
committed
update README
1 parent 4a9b236 commit d7014b9

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ hello
1919
world
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
2455
auto 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

0 commit comments

Comments
 (0)