rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.4k stars 626 forks source link

Iterator function `next()` takes mutable ownership #2696

Closed sham789 closed 1 year ago

sham789 commented 1 year ago

Why this function needs &mut self?

https://github.com/rust-lang/futures-rs/blob/41478f5e69dddc51939c2695cd6f66d6b7b70d54/futures-util/src/stream/stream/mod.rs#L287-L292

I found this issue while I was trying to spawn 2 distinct threads where:

  1. One would iterate on incoming messages.
  2. Second would send ping messages.

Basically, having this &mut self I can't wrap the ws stream into Arc<RwLock<WebSocketStream>> to achieve my requirements