// Copyright 2018-2025 the Deno authors. MIT license. #[cfg(not(target_arch = "wasm32"))] use deno_unsync::JoinHandle; #[cfg(target_arch = "wasm32")] pub type JoinHandle = std::future::Ready>; pub fn spawn_blocking< F: (FnOnce() -> R) + Send + 'static, R: Send + 'static, >( f: F, ) -> JoinHandle { #[cfg(target_arch = "wasm32")] { let result = f(); std::future::ready(Ok(result)) } #[cfg(not(target_arch = "wasm32"))] { deno_unsync::spawn_blocking(f) } } #[cfg(not(target_arch = "wasm32"))] pub use deno_unsync::sync::MultiRuntimeAsyncValueCreator; #[cfg(target_arch = "wasm32")] mod wasm { use futures::future::LocalBoxFuture; type CreateFutureFn = Box LocalBoxFuture<'static, TResult> + Send + Sync>; pub struct MultiRuntimeAsyncValueCreator { create_future: CreateFutureFn, } impl std::fmt::Debug for MultiRuntimeAsyncValueCreator { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("MultiRuntimeAsyncValueCreator").finish() } } impl MultiRuntimeAsyncValueCreator { pub fn new(create_future: CreateFutureFn) -> Self { Self { create_future } } pub async fn get(&self) -> TResult { (self.create_future)().await } } } #[cfg(target_arch = "wasm32")] pub use wasm::MultiRuntimeAsyncValueCreator;