Files
windmill/rust-client/src/maybe_future.rs
T
pyranota 332f66e348 feat(rust): add rust sdk (#5909)
* 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
2025-06-10 18:38:18 +02:00

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()
});