bevy_platform/
thread.rs

1//! Provides `sleep` for all platforms.
2
3pub use thread::sleep;
4
5cfg_if::cfg_if! {
6    // TODO: use browser timeouts based on ScheduleRunnerPlugin::build
7    if #[cfg(feature = "std")] {
8        use std::thread;
9    } else {
10        mod fallback {
11            use core::{hint::spin_loop, time::Duration};
12
13            use crate::time::Instant;
14
15            /// Puts the current thread to sleep for at least the specified amount of time.
16            ///
17            /// As this is a `no_std` fallback implementation, this will spin the current thread.
18            pub fn sleep(dur: Duration) {
19                let start = Instant::now();
20
21                while start.elapsed() < dur {
22                    spin_loop()
23                }
24            }
25        }
26
27        use fallback as thread;
28    }
29}