#![warn(missing_docs)]
pub mod test;
pub mod time;
mod lock;
pub use lock::*;
pub mod value;
mod cancellation_token;
pub use cancellation_token::*;
#[cfg(not(target_arch = "wasm32"))]
pub use tokio::{
spawn,
task::{JoinError, JoinHandle},
};
#[cfg(target_arch = "wasm32")]
pub use js_utils::spawn::*;
pub use dportable_macros::create_non_sync_send_variant_for_wasm;
#[cfg(target_arch = "wasm32")]
pub fn random() -> f64 {
js_sys::Math::random()
}
#[cfg(not(target_arch = "wasm32"))]
pub fn random() -> f64 {
rand::random()
}
#[cfg(test)]
mod tests {
use crate::{create_non_sync_send_variant_for_wasm, test::dtest};
use super::spawn;
#[dtest]
async fn test_spawn() {
let result = spawn(async move { 4 });
assert_eq!(4, result.await.unwrap());
}
#[dtest]
async fn test_create_non_sync_send_variant_for_wasm() {
struct Hello {
#[cfg(target_arch = "wasm32")]
_some_reference: std::rc::Rc<()>,
#[cfg(not(target_arch = "wasm32"))]
_some_reference: std::sync::Arc<()>,
}
create_non_sync_send_variant_for_wasm! {
trait SomeTrait: Send {
fn hello(&self);
}
}
impl SomeTrait for Hello {
fn hello(&self) {
println!("Hello!");
}
}
let hello = Hello {
_some_reference: Default::default(),
};
spawn(async move {
hello.hello();
});
}
}