Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM support #71

Open
flupke opened this issue Jul 15, 2024 · 2 comments
Open

WASM support #71

flupke opened this issue Jul 15, 2024 · 2 comments

Comments

@flupke
Copy link

flupke commented Jul 15, 2024

I get this error when trying to build for wasm:

   Compiling async-broadcast v0.7.1
error[E0599]: no method named `wait` found for struct `SendInner` in the current scope
    --> /home/flupke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-broadcast-0.7.1/src/lib.rs:1647:1
     |
1647 | / easy_wrapper! {
1648 | |     /// A future returned by [`Sender::broadcast()`].
1649 | |     #[derive(Debug)]
1650 | |     #[must_use = "futures do nothing unless .awaited"]
1651 | |     pub struct Send<'a, T: Clone>(SendInner<'a, T> => Result<Option<T>, SendError<T>>);
1652 | |     pub(crate) wait();
1653 | | }
     | |_^ method not found in `SendInner<'_, T>`
1654 |
1655 | / pin_project! {
1656 | |     #[derive(Debug)]
1657 | |     struct SendInner<'a, T> {
1658 | |         sender: &'a Sender<T>,
...    |
1665 | |     }
1666 | | }
     | |_- method `wait` not found for this struct
     |
     = help: items from traits can only be used if the trait is implemented and in scope
     = note: the following trait defines an item `wait`, perhaps you need to implement it:
             candidate #1: `Strategy`
     = note: this error originates in the macro `easy_wrapper` (in Nightly builds, run with -Z macro-backtrace for more info)

which is caused by this in the event-listener-strategy crate:

    /// Wait for the future to complete, blocking the current thread.
    ///
    /// This function uses the [`Blocking`] strategy to poll the future until it is ready.
    ///
    /// The future should only return `Pending` if `Strategy::poll` returns error. Otherwise,
    /// this function polls the future in a hot loop.
    #[cfg(all(feature = "std", not(target_family = "wasm")))]
    #[cfg_attr(docsrs, doc(all(feature = "std", not(target_family = "wasm"))))]
    fn wait(mut self) -> Self::Output
    where
        Self: Sized,
    {
        // SAFETY: `self`/`this` is not moved out after this.
        let mut this = unsafe { Pin::new_unchecked(&mut self) };

        loop {
            if let Poll::Ready(res) = this
                .as_mut()
                .poll_with_strategy(&mut Blocking::default(), &mut ())
            {
                return res;
            }
        }
    }

Do you think it would be possible to add WASM support behind a feature flag, or is this fundamentally needed?

@notgull
Copy link
Member

notgull commented Oct 29, 2024

This crate relies on RwLock, so I don't think WASM support would work.

@zeenix
Copy link
Member

zeenix commented Oct 29, 2024

This crate relies on RwLock, so I don't think WASM support would work.

Good point. Would a Mutex be possible? We can always have conditional code to use a RwLock only for WASM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants