I'm trying to implement a wrapper around web socket connection. One of the types, WebSocket type from web_sys, is !Send
.
So I end up that my wrapper is also !Send
, even if everything is inside Arc<Mutex<>>
.
Current code for my wrapper is like this, this is not the actual code
struct Ws {
Arc<Mutex<{
actual_websocket,
inbox,
outbox,
}>>
}
impl Ws {
fn new() {
let me = Self{...};
spawn async {
loop {
// send data from outbox to actual websocket
// read data from actual websocket into inbox
}
}
me
}
fn send() { put into outbox }
fn read() { pop from inbox }
}
So, it looks like I can solve the problem by not storing the web socket in the Ws struct, leaving it owned by the async closure. But I'm not too fond of this approach. Maybe it's just a habit from my previous experience with other languages, but I want to have a reference to it, at least I would be able to use it for debugging. What else can I do?