Skip to main content

icechunk/
compat.rs

1// Conditional Send bound for WASM compatibility.
2// Single-threaded WASM does not need `Send`, and some dependencies
3// (e.g. backon's GlooTimersSleep) are not `Send` there.
4// Enable `napi-send-contract` to force `Send` futures on WASM for napi compatibility checks.
5
6use std::{future::Future, pin::Pin};
7
8#[cfg(any(not(target_family = "wasm"), feature = "napi-send-contract"))]
9pub type IcechunkBoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
10
11#[cfg(all(target_family = "wasm", not(feature = "napi-send-contract")))]
12pub type IcechunkBoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
13
14#[cfg(any(not(target_family = "wasm"), feature = "napi-send-contract"))]
15macro_rules! ic_boxed {
16    ($fut:expr) => {
17        futures::FutureExt::boxed($fut)
18    };
19}
20
21#[cfg(all(target_family = "wasm", not(feature = "napi-send-contract")))]
22macro_rules! ic_boxed {
23    ($fut:expr) => {
24        futures::FutureExt::boxed_local($fut)
25    };
26}
27
28pub(crate) use ic_boxed;