freya_core/io/thread.rs
1use std::future::Future;
2
3/// Runs a blocking closure off the caller's thread.
4#[cfg(not(target_os = "emscripten"))]
5pub fn thread<T: Send + 'static>(
6 function: impl FnOnce() -> T + Send + 'static,
7) -> impl Future<Output = T> {
8 blocking::unblock(function)
9}
10
11/// Runs a blocking closure inline.
12#[cfg(target_os = "emscripten")]
13pub fn thread<T: Send + 'static>(
14 function: impl FnOnce() -> T + Send + 'static,
15) -> impl Future<Output = T> {
16 std::future::ready(function())
17}