Skip to content

Commit d5e770d

Browse files
committed
use elapsed on instant (#4599)
# Objective - reopen #4497 on main - Make the example a tiny bit more elegant
1 parent dafd7a1 commit d5e770d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

examples/async_tasks/async_compute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res<AsyncComputeTaskPool>) {
5959
let mut rng = rand::thread_rng();
6060
let start_time = Instant::now();
6161
let duration = Duration::from_secs_f32(rng.gen_range(0.05..0.2));
62-
while Instant::now() - start_time < duration {
62+
while start_time.elapsed() < duration {
6363
// Spinning for 'duration', simulating doing hard
6464
// compute work generating translation coords!
6565
}

examples/async_tasks/external_source_external_thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
3232
let mut rng = rand::thread_rng();
3333
let start_time = Instant::now();
3434
let duration = Duration::from_secs_f32(rng.gen_range(0.0..0.2));
35-
while Instant::now() - start_time < duration {
35+
while start_time.elapsed() < duration {
3636
// Spinning for 'duration', simulating doing hard work!
3737
}
3838

0 commit comments

Comments
 (0)