fedimint_core/
runtime.rs
1use std::future::Future;
5
6use fedimint_logging::LOG_RUNTIME;
7pub use n0_future::task::{JoinError, JoinHandle};
8pub use n0_future::time::{Duration, Elapsed, Instant, sleep, sleep_until, timeout};
9use tracing::Instrument;
10
11use crate::task::MaybeSend;
12
13pub fn spawn<F, T>(name: &str, future: F) -> JoinHandle<T>
14where
15 F: Future<Output = T> + 'static + MaybeSend,
16 T: MaybeSend + 'static,
17{
18 let span = tracing::debug_span!(target: LOG_RUNTIME, parent: None, "spawn", task = name);
19 n0_future::task::spawn(future.instrument(span))
20}
21
22#[cfg(not(target_family = "wasm"))]
25pub fn block_in_place<F, R>(f: F) -> R
26where
27 F: FnOnce() -> R,
28{
29 tokio::task::block_in_place(f)
31}
32
33#[cfg(not(target_family = "wasm"))]
34pub fn block_on<F: Future>(future: F) -> F::Output {
35 tokio::runtime::Handle::current().block_on(future)
37}