smol-rs / async-broadcast

Async broadcast channels
Apache License 2.0
151 stars 26 forks source link

Compiling for wasm32-unknown-unknown fails inside event-listener-strategy #50

Closed Ekleog closed 1 month ago

Ekleog commented 5 months ago

The error message looks like:

error[E0599]: no method named `wait` found for struct `Pin<&'evl mut EventListener>` in the current scope
   --> /home/ekleog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/event-listener-strategy-0.1.0/src/lib.rs:479:13
    |
479 |         evl.wait();
    |             ^^^^ method not found in `Pin<&mut EventListener>`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following traits define an item `wait`, perhaps you need to implement one of them:
            candidate #1: `EventListenerFuture`
            candidate #2: `Strategy`

I'm currently looking for a workaround, because event-listener definitely seems to support wasm32-unknown-unknown. But currently my only idea, aka default_features = false, features = ["portable-atomic"] is without any success.

My current status is this crate, initialized with cargo init --bin and with only the Cargo.toml modified this way, built with cargo build --target=wasm32-unknown-unknown:

[package]
name = "foobar"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-broadcast = "0.6.0"
event-listener = { version = "3.0", default-features = false, features = ["portable-atomic"] }

I have also tried with the latest rust nightly without success, to make it less likely it's a bug in the specific nightly I had pinned.

Incidentally, it looks like event-listener released a v4 and event-listener-strategy released a v0.4, it might be worth updating async-broadcast?

I'm open to any ideas, and will continue searching on my side :)

Ekleog commented 5 months ago

Seems like bumping the dependencies fixes the issue, see #51 for a suggested fix (disclaimer: I have no idea what I'm doing, I just fiddled until things built and checked that the added #[cfg] was reasonable enough :))

lf-wxp commented 4 months ago

in version 0.7.0, seems have the familiar issue, even though event-listener is 5.0 and event-listener-strategy is 0.5.


error[E0599]: no method named `wait` found for struct `SendInner` in the current scope
    --> /Users/xxx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-broadcast-0.7.0/src/lib.rs:1595:1
     |
1595 | / easy_wrapper! {
1596 | |     /// A future returned by [`Sender::broadcast()`].
1597 | |     #[derive(Debug)]
1598 | |     #[must_use = "futures do nothing unless .awaited"]
1599 | |     pub struct Send<'a, T: Clone>(SendInner<'a, T> => Result<Option<T>, SendError<T>>);
1600 | |     pub(crate) wait();
1601 | | }
     | |_^ method not found in `SendInner<'_, T>`
1602 |
1603 | / pin_project! {
1604 | |     #[derive(Debug)]
1605 | |     struct SendInner<'a, T> {
1606 | |         sender: &'a Sender<T>,
...    |
1613 | |     }
1614 | | }
     | |_- 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)

error[E0599]: no method named `wait` found for struct `RecvInner` in the current scope
    --> /Users/xxx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-broadcast-0.7.0/src/lib.rs:1667:1
     |
1667 | / easy_wrapper! {
1668 | |     /// A future returned by [`Receiver::recv()`].
1669 | |     #[derive(Debug)]
1670 | |     #[must_use = "futures do nothing unless .awaited"]
1671 | |     pub struct Recv<'a, T: Clone>(RecvInner<'a, T> => Result<T, RecvError>);
1672 | |     pub(crate) wait();
1673 | | }
     | |_^ method not found in `RecvInner<'_, T>`
1674 |
1675 | / pin_project! {
1676 | |     #[derive(Debug)]
1677 | |     struct RecvInner<'a, T> {
1678 | |         receiver: &'a mut Receiver<T>,
...    |
1684 | |     }
1685 | | }
     | |_- method `wait` not found for this struct
`
zeenix commented 4 months ago

Is this still valid with the latest release?

lf-wxp commented 4 months ago

Here is the code. https://github.com/lf-wxp/rust-practice/tree/main/yew-await

in version 0.7.0, seems have the familiar issue, even though event-listener is 5.0 and event-listener-strategy is 0.5.

error[E0599]: no method named `wait` found for struct `SendInner` in the current scope
    --> /Users/xxx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-broadcast-0.7.0/src/lib.rs:1595:1
     |
1595 | / easy_wrapper! {
1596 | |     /// A future returned by [`Sender::broadcast()`].
1597 | |     #[derive(Debug)]
1598 | |     #[must_use = "futures do nothing unless .awaited"]
1599 | |     pub struct Send<'a, T: Clone>(SendInner<'a, T> => Result<Option<T>, SendError<T>>);
1600 | |     pub(crate) wait();
1601 | | }
     | |_^ method not found in `SendInner<'_, T>`
1602 |
1603 | / pin_project! {
1604 | |     #[derive(Debug)]
1605 | |     struct SendInner<'a, T> {
1606 | |         sender: &'a Sender<T>,
...    |
1613 | |     }
1614 | | }
     | |_- 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)

error[E0599]: no method named `wait` found for struct `RecvInner` in the current scope
    --> /Users/xxx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-broadcast-0.7.0/src/lib.rs:1667:1
     |
1667 | / easy_wrapper! {
1668 | |     /// A future returned by [`Receiver::recv()`].
1669 | |     #[derive(Debug)]
1670 | |     #[must_use = "futures do nothing unless .awaited"]
1671 | |     pub struct Recv<'a, T: Clone>(RecvInner<'a, T> => Result<T, RecvError>);
1672 | |     pub(crate) wait();
1673 | | }
     | |_^ method not found in `RecvInner<'_, T>`
1674 |
1675 | / pin_project! {
1676 | |     #[derive(Debug)]
1677 | |     struct RecvInner<'a, T> {
1678 | |         receiver: &'a mut Receiver<T>,
...    |
1684 | |     }
1685 | | }
     | |_- method `wait` not found for this struct
`