From a58195d8c7185f353eab172a897d6782fd77a070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 26 Apr 2022 18:42:44 +0000 Subject: [PATCH] use elapsed on instant (#4599) # Objective - reopen #4497 on main - Make the example a tiny bit more elegant --- examples/async_tasks/async_compute.rs | 2 +- examples/async_tasks/external_source_external_thread.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/async_tasks/async_compute.rs b/examples/async_tasks/async_compute.rs index e5f7e30d8b0ab3..9182ac48797fd5 100644 --- a/examples/async_tasks/async_compute.rs +++ b/examples/async_tasks/async_compute.rs @@ -59,7 +59,7 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res) { 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! } diff --git a/examples/async_tasks/external_source_external_thread.rs b/examples/async_tasks/external_source_external_thread.rs index 4e64cb58aa2331..6b2cec163c2b11 100644 --- a/examples/async_tasks/external_source_external_thread.rs +++ b/examples/async_tasks/external_source_external_thread.rs @@ -32,7 +32,7 @@ fn setup(mut commands: Commands, asset_server: Res) { 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! }