bevy_platform/
thread.rs

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