Skip to content

Commit e7cf5b5

Browse files
Jeff Laijefftt
Jeff Lai
authored andcommitted
Remove examples/busy_loop.rs, update examples/app.rs
1 parent 03d4160 commit e7cf5b5

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

console-subscriber/examples/app.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ OPTIONS:
1111
blocks Includes a (misbehaving) blocking task
1212
burn Includes a (misbehaving) task that spins CPU with self-wakes
1313
coma Includes a (misbehaving) task that forgets to register a waker
14+
noyield Includes a (misbehaving) task that spawns tasks that never yield
1415
"#;
1516

1617
#[tokio::main]
@@ -38,6 +39,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
3839
.spawn(burn(1, 10))
3940
.unwrap();
4041
}
42+
"noyield" => {
43+
tokio::task::Builder::new()
44+
.name("noyield")
45+
.spawn(no_yield(20))
46+
.unwrap();
47+
}
4148
"help" | "-h" => {
4249
eprintln!("{}", HELP);
4350
return Ok(());
@@ -114,3 +121,17 @@ async fn burn(min: u64, max: u64) {
114121
}
115122
}
116123
}
124+
125+
#[tracing::instrument]
126+
async fn no_yield(seconds: u64) {
127+
loop {
128+
let handle = tokio::task::Builder::new()
129+
.name("greedy")
130+
.spawn(async move {
131+
std::thread::sleep(Duration::from_secs(seconds));
132+
})
133+
.expect("Couldn't spawn greedy task");
134+
135+
_ = handle.await;
136+
}
137+
}

console-subscriber/examples/busy_loop.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)