snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

Pass sink into other threads. #259

Closed uwejan closed 1 year ago

uwejan commented 1 year ago

I wonder if there is a way to have sink as mutable and being able to clone it.

        let (ws_stream, _) = connect_async(url).await.expect("Failed to connect");

        let (sink, stream) = ws_stream.split();

        let sc = sink.clone();

Semilare issue with actix mentioned a while a go, which suggested using tokio Framed. https://github.com/actix/actix/issues/371

daniel-abramov commented 1 year ago

This solely depends on your needs. Generally it's not specific to tungstenite or tokio-tungstenite, but a regular way to work with thread and Send and Sync in Rust. I.e. you could wrap it in Mutex and wrap Mutex in Arc if that's the behavior that you expect.

We've had the same question some time ago: https://github.com/snapview/tokio-tungstenite/issues/123#issuecomment-1163263205