File: malformed.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 (31 lines) | stat: -rw-r--r-- 867 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
//! This example showcases what NOT to do. Avoid spawning tasks that are NOT
//! annotated with `#[async_backtrace::framed]`. If such tasks are spawned, and
//! they include invocations of functions that ARE annotated with
//! `#[async_backtrace::framed]`, these sub-routines will appear as distinct
//! tasks. This is both misleading, and more computationally expensive.
//!
//! Uncomment the attribute on `selecting()` to make this example behave well.

#[tokio::main]
async fn main() {
    selecting().await;
}

/* #[async_backtrace::framed] */
async fn selecting() {
    tokio::select! {
        biased;
        _ = yielding() => {}
        _ = ready() => {}
    };
}

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

#[async_backtrace::framed]
async fn ready() {
    println!("{}", async_backtrace::taskdump_tree(true));
}