Skip to main content

bark_runtime/
lib.rs

1//! Runtime abstractions for native and WASM compatibility.
2//!
3//! This crate provides abstractions over async runtime functionality
4//! to support both native (tokio) and WASM (wasm-bindgen) environments.
5
6pub mod cancel;
7pub mod clock;
8pub mod sleep;
9pub mod task;
10pub mod timeout;
11
12pub use cancel::CancellationToken;
13pub use clock::{now, timestamp_secs, Instant, SystemTime, UNIX_EPOCH};
14pub use sleep::sleep;
15pub use task::spawn;
16pub use timeout::{timeout, Elapsed};
17
18/// A trait that requires [Send] on native platforms and nothing on WASM,
19/// where the runtime is single-threaded and futures often aren't [Send].
20#[cfg(not(target_arch = "wasm32"))]
21pub trait MaybeSend: Send {}
22#[cfg(not(target_arch = "wasm32"))]
23impl<T: Send> MaybeSend for T {}
24
25/// A trait that requires [Send] on native platforms and nothing on WASM,
26/// where the runtime is single-threaded and futures often aren't [Send].
27#[cfg(target_arch = "wasm32")]
28pub trait MaybeSend {}
29#[cfg(target_arch = "wasm32")]
30impl<T> MaybeSend for T {}
31
32/// A trait that requires [Sync] on native platforms and nothing on WASM.
33#[cfg(not(target_arch = "wasm32"))]
34pub trait MaybeSync: Sync {}
35#[cfg(not(target_arch = "wasm32"))]
36impl<T: Sync> MaybeSync for T {}
37
38/// A trait that requires [Sync] on native platforms and nothing on WASM.
39#[cfg(target_arch = "wasm32")]
40pub trait MaybeSync {}
41#[cfg(target_arch = "wasm32")]
42impl<T> MaybeSync for T {}