Skip to content

Relax Send bounds on single-threaded wasm targets #307

Description

@sagikazarmark

Problem

Connection is Send throughout the library:

  • ConnectTo<R: Role>: Send + 'static
  • fn connect_to(...) -> impl Future<Output = Result<()>> + Send
  • Role: Debug + Clone + Send + Sync + 'static + Eq + Ord + Hash
  • handler futures return impl Future<...> + Send
  • SessionBlockState: Send + 'static + Sync
  • BoxFuture (which is Send) rather than LocalBoxFuture at every boxed-future site

The doc comment on connect_to states it outright: "The future must be Send."

Since the wasm target gating landed, the crate compiles for wasm32-unknown-unknown, but browser runtimes are single-threaded and the surrounding types (web_sys::WebSocket, js_sys handles, Dioxus/Leptos/yew signals, Rc/RefCell) are !Send.

Impact

Adoption is possible but requires wrapping the SDK: handlers forward plain data into a futures::mpsc, and the !Send world drains it on the far side.

It works, but it is a layer added rather than a layer removed, which weakens the case for adopting the SDK over a hand-rolled client in the first place.

Proposal

Conditionally relax the bounds for WASM:

#[cfg(not(target_family = "wasm"))]
pub trait MaybeSend: Send {}
#[cfg(not(target_family = "wasm"))]
impl<T: Send> MaybeSend for T {}

#[cfg(target_family = "wasm")]
pub trait MaybeSend {}
#[cfg(target_family = "wasm")]
impl<T> MaybeSend for T {}

plus a MaybeSendBoxFuture<'a, T> alias.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions