use elapsed on instant (#4599)

# Objective

- reopen #4497 on main
- Make the example a tiny bit more elegant
This commit is contained in:
François 2022-04-26 18:42:44 +00:00
parent dafd7a14c9
commit d5e770dfcb
2 changed files with 2 additions and 2 deletions

View File

@ -59,7 +59,7 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res<AsyncComputeTaskPool>) {
let mut rng = rand::thread_rng();
let start_time = Instant::now();
let duration = Duration::from_secs_f32(rng.gen_range(0.05..0.2));
while Instant::now() - start_time < duration {
while start_time.elapsed() < duration {
// Spinning for 'duration', simulating doing hard
// compute work generating translation coords!
}

View File

@ -32,7 +32,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut rng = rand::thread_rng();
let start_time = Instant::now();
let duration = Duration::from_secs_f32(rng.gen_range(0.0..0.2));
while Instant::now() - start_time < duration {
while start_time.elapsed() < duration {
// Spinning for 'duration', simulating doing hard work!
}