bevy/crates/bevy_tasks/examples/idle_behavior.rs
Cyrill Schenkel 8570af1d96
Add print_stdout and print_stderr lints (#17446) (#18233)
# Objective

- Prevent usage of `println!`, `eprintln!` and the like because they
require `std`
- Fixes #17446

## Solution

- Enable the `print_stdout` and `print_stderr` clippy lints
- Replace all `println!` and `eprintln!` occurrences with `log::*` where
applicable or alternatively ignore the warnings

## Testing

- Run `cargo clippy --workspace` to ensure that there are no warnings
relating to printing to `stdout` or `stderr`
2025-03-11 19:35:48 +00:00

36 lines
1.1 KiB
Rust

//! This sample demonstrates a thread pool with one thread per logical core and only one task
//! spinning. Other than the one thread, the system should remain idle, demonstrating good behavior
//! for small workloads.
#![expect(clippy::print_stdout, reason = "Allowed in examples.")]
use bevy_platform_support::time::Instant;
use bevy_tasks::TaskPoolBuilder;
use core::time::Duration;
fn main() {
let pool = TaskPoolBuilder::new()
.thread_name("Idle Behavior ThreadPool".to_string())
.build();
pool.scope(|s| {
for i in 0..1 {
s.spawn(async move {
println!("Blocking for 10 seconds");
let now = Instant::now();
while Instant::now() - now < Duration::from_millis(10000) {
// spin, simulating work being done
}
println!(
"Thread {:?} index {} finished",
std::thread::current().id(),
i
);
});
}
});
println!("all tasks finished");
}