#[allow(unused_imports)]
use cfg_if::cfg_if;
use futures::Future;
cfg_if! {
if #[cfg(not(any(target_arch = "wasm32", target_arch = "bpf")))] {
pub mod native {
pub use super::*;
pub use tokio::task::yield_now as yield_executor;
pub use tokio::task::yield_now;
pub use tokio::time::sleep;
pub use crate::native::interval::{interval,Interval};
pub fn spawn<F, T>(future: F)
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
tokio::task::spawn(future);
}
pub fn dispatch<F, T>(_future: F)
where
F: Future<Output = T> + 'static,
T: 'static,
{
unreachable!()
}
pub use workflow_core_macros::call_async_no_send;
}
pub use native::*;
}
}
pub mod wasm {
pub use super::*;
pub fn spawn<F, T>(_future: F)
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
async_std::task::block_on(_future);
} else {
panic!("workflow_core::task::wasm::spawn() is not allowed on non-wasm target");
}
}
}
pub fn dispatch<F, T>(_future: F)
where
F: Future<Output = T> + 'static,
T: 'static,
{
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
async_std::task::block_on(_future);
} else {
panic!("workflow_core::task::wasm::spawn() is not allowed on non-wasm target");
}
}
}
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
pub use crate::wasm::{
overrides::disable_persistent_timer_overrides,
interval::{interval,Interval},
yield_executor::{yield_executor,Yield},
sleep::{sleep,Sleep}
};
pub use async_std::task::yield_now;
pub use workflow_core_macros::call_async_no_send;
} else {
pub use crate::native::{
overrides::disable_persistent_timer_overrides,
interval::{interval,Interval},
};
pub use async_std::task::sleep;
pub use async_std::task::yield_now;
pub use workflow_core_macros::call_async_no_send;
}
}
}
#[cfg(target_arch = "wasm32")]
pub use wasm::*;