Synchronously run an async future from a non-async function. - If we're already inside a Tokio runtime, we switch to the blocking pool and `block_on` the future (prevents scheduler starvation). - Otherwise, we use a shared, long-lived runtime.
(fut: F)
| 31 | /// and `block_on` the future (prevents scheduler starvation). |
| 32 | /// - Otherwise, we use a shared, long-lived runtime. |
| 33 | pub fn run_blocking<F, T>(fut: F) -> T |
| 34 | where |
| 35 | F: std::future::Future<Output = T> + Send + 'static, |
| 36 | T: Send + 'static, |
| 37 | { |
| 38 | match Handle::try_current() { |
| 39 | Ok(handle) => tokio::task::block_in_place(|| handle.block_on(fut)), |
| 40 | Err(_) => runtime().block_on(fut), |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | pub(crate) fn build_javascript(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> { |
| 45 | let cwd = fs::canonicalize(project_path)?; |
no test coverage detected
searching dependent graphs…