#[allow(unused_imports)]
use cfg_if::cfg_if;
use futures::Future;
#[doc(hidden)]
pub mod __yield {
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
pub async fn yield_now() {
struct YieldNow(bool);
impl Future for YieldNow {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
if self.0 {
Poll::Ready(())
} else {
self.0 = true;
cx.waker().wake_by_ref();
Poll::Pending
}
}
}
YieldNow(false).await
}
}
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")] {
wasm_bindgen_futures::spawn_local(async move {
let _ = _future.await;
});
} 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")] {
wasm_bindgen_futures::spawn_local(async move {
let _ = _future.await;
});
} 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 crate::task::__yield::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 tokio::time::sleep;
pub use tokio::task::yield_now;
pub use workflow_core_macros::call_async_no_send;
}
}
}
#[cfg(target_arch = "wasm32")]
pub use wasm::*;