Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
std::thread::sleep
instead of spin-waiting in the async_compute…
… example (#11856) # Objective - The [`async_compute` example](https://github.com/bevyengine/bevy/blob/77c26f64ce0c1a538629a544b7020eb2d2b77466/examples/async_tasks/async_compute.rs#L65-L68) uses a busy loop. - It's good practice to mark busy loops with the [`std::hint::spin_loop`](https://doc.rust-lang.org/stable/std/hint/fn.spin_loop.html) function. ## Solution - Call [`std::hint::spin_loop`](https://doc.rust-lang.org/stable/std/hint/fn.spin_loop.html) within the busy loop. ## Discussion - While it is good practice to mark busy loops with `spin_loop`, it does somewhat increase cognitive complexity. Since it is an example, it does not matter too much. - This is somewhat mitigated by the fact that it is within [`std::hint`](https://doc.rust-lang.org/stable/std/hint/index.html), which only affects compilation and doesn't do anything. - Should I add a comment on what `spin_loop` does? - Should the `while` loop just be replaced with `std::thread::sleep`?
- Loading branch information