Skip to content

Commit

Permalink
Remove examples/busy_loop.rs, update examples/app.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftt committed Jul 12, 2023
1 parent 71a5528 commit 37154c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
21 changes: 21 additions & 0 deletions console-subscriber/examples/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ OPTIONS:
blocks Includes a (misbehaving) blocking task
burn Includes a (misbehaving) task that spins CPU with self-wakes
coma Includes a (misbehaving) task that forgets to register a waker
noyield Includes a (misbehaving) task that spawns tasks that never yield
"#;

#[tokio::main]
Expand Down Expand Up @@ -38,6 +39,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.spawn(burn(1, 10))
.unwrap();
}
"noyield" => {
tokio::task::Builder::new()
.name("noyield")
.spawn(no_yield(20))
.unwrap();
}
"help" | "-h" => {
eprintln!("{}", HELP);
return Ok(());
Expand Down Expand Up @@ -114,3 +121,17 @@ async fn burn(min: u64, max: u64) {
}
}
}

#[tracing::instrument]
async fn no_yield(seconds: u64) {
loop {
let handle = tokio::task::Builder::new()
.name("greedy")
.spawn(async move {
std::thread::sleep(Duration::from_secs(seconds));
})
.expect("Couldn't spawn greedy task");

_ = handle.await;
}
}
31 changes: 0 additions & 31 deletions console-subscriber/examples/busy_loop.rs

This file was deleted.

0 comments on commit 37154c0

Please sign in to comment.