File: taskdump.rs

package info (click to toggle)
rust-async-backtrace 0.2.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// This example outputs something like:
// ╼ taskdump::foo::{{closure}} at backtrace/examples/taskdump.rs:20:1
//   └╼ taskdump::bar::{{closure}} at backtrace/examples/taskdump.rs:25:1
//      ├╼ taskdump::buz::{{closure}} at backtrace/examples/taskdump.rs:35:1
//      │  └╼ taskdump::baz::{{closure}} at backtrace/examples/taskdump.rs:40:1
//      └╼ taskdump::fiz::{{closure}} at backtrace/examples/taskdump.rs:30:1
// ╼ taskdump::pending::{{closure}} at backtrace/examples/taskdump.rs:15:1

#[tokio::main]
async fn main() {
    tokio::select! {
        _ = tokio::spawn(pending()) => {}
        _ = foo() => {}
    };
}

#[async_backtrace::framed]
async fn pending() {
    std::future::pending::<()>().await
}

#[async_backtrace::framed]
async fn foo() {
    bar().await;
}

#[async_backtrace::framed]
async fn bar() {
    futures::join!(fiz(), buz());
}

#[async_backtrace::framed]
async fn fiz() {
    tokio::task::yield_now().await;
}

#[async_backtrace::framed]
async fn buz() {
    println!("{}", baz().await);
}

#[async_backtrace::framed]
async fn baz() -> String {
    async_backtrace::taskdump_tree(true)
}