
# Objective The goal of `bevy_platform_support` is to provide a set of platform agnostic APIs, alongside platform-specific functionality. This is a high traffic crate (providing things like HashMap and Instant). Especially in light of https://github.com/bevyengine/bevy/discussions/18799, it deserves a friendlier / shorter name. Given that it hasn't had a full release yet, getting this change in before Bevy 0.16 makes sense. ## Solution - Rename `bevy_platform_support` to `bevy_platform`.
30 lines
799 B
Rust
30 lines
799 B
Rust
//! Provides `sleep` for all platforms.
|
|
|
|
pub use thread::sleep;
|
|
|
|
cfg_if::cfg_if! {
|
|
// TODO: use browser timeouts based on ScheduleRunnerPlugin::build
|
|
if #[cfg(feature = "std")] {
|
|
use std::thread;
|
|
} else {
|
|
mod fallback {
|
|
use core::{hint::spin_loop, time::Duration};
|
|
|
|
use crate::time::Instant;
|
|
|
|
/// Puts the current thread to sleep for at least the specified amount of time.
|
|
///
|
|
/// As this is a `no_std` fallback implementation, this will spin the current thread.
|
|
pub fn sleep(dur: Duration) {
|
|
let start = Instant::now();
|
|
|
|
while start.elapsed() < dur {
|
|
spin_loop()
|
|
}
|
|
}
|
|
}
|
|
|
|
use fallback as thread;
|
|
}
|
|
}
|