mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-18 16:02:10 +00:00
332f66e348
* upload client * add gh workflow * refactor build script * remove dbg! * fix async * remove unused * update dev.nu * update CI * fix ci * fixin tests * fixes + tests
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
// #[cfg(feature = "async")]
|
|
// use futures::future::BoxFuture;
|
|
|
|
/// A conditional type that represents either:
|
|
/// - A boxed future (async mode)
|
|
/// - A direct value (sync mode)
|
|
pub mod maybe_future {
|
|
#[cfg(feature = "async")]
|
|
pub type MaybeFuture<'a, T> = futures::future::BoxFuture<'a, T>;
|
|
#[cfg(not(feature = "async"))]
|
|
pub type MaybeFuture<'a, T> = T;
|
|
}
|
|
|
|
/// Bridges between async and sync execution contexts
|
|
///
|
|
/// Behavior depends on compilation:
|
|
/// - With `async` feature: Returns a boxed future
|
|
/// - Without `async` feature: Blocks on the global runtime
|
|
#[macro_export]
|
|
macro_rules! ret {
|
|
($ex:expr) => {
|
|
#[cfg(feature = "async")]
|
|
return async move { $ex.await }.boxed();
|
|
|
|
#[cfg(not(feature = "async"))]
|
|
return crate::maybe_future::RUNTIME.block_on($ex);
|
|
};
|
|
}
|
|
|
|
/// The global Tokio runtime instance used in sync mode
|
|
///
|
|
/// Initialized lazily with:
|
|
/// - I/O capabilities
|
|
/// - Time utilities
|
|
/// - Current-thread executor
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// If Tokio fails to initialize the runtime
|
|
#[cfg(not(feature = "async"))]
|
|
pub(crate) static RUNTIME: once_cell::sync::Lazy<tokio::runtime::Runtime> =
|
|
once_cell::sync::Lazy::new(|| {
|
|
tokio::runtime::Builder::new_current_thread()
|
|
.enable_io()
|
|
.enable_time()
|
|
.build()
|
|
.unwrap()
|
|
});
|