reqwasm icon indicating copy to clipboard operation
reqwasm copied to clipboard

Implement `Clone` for `WebSocket`

Open lukechu10 opened this issue 3 years ago • 3 comments

The problem with WebSocket after using .split() is that we can no longer access the methods on the WebSocket, e.g. .close(). This issue would be solved if the WebSocket could be cloned. It would also be nice to expose a method to get the underlying web_sys::WebSocket for finer-grained control not available directly in the library.

lukechu10 avatar Mar 11 '22 05:03 lukechu10

WebSocket used to be Clone but it was removed. See https://github.com/hamza1311/reqwasm/commit/445e9a5bf555a0e37d0ff7fb71e69d34cb8f2493 for details.

If you can think of any other way to solve this problem, I would be happy to hear it.

Side note: this project is moving into gloo so any changes will happen there

ranile avatar Mar 11 '22 09:03 ranile

If you can think of any other way to solve this problem, I would be happy to hear it.

You can wrap the WebSocket with a Rc and only close the web socket when the strong count drops to 0.

lukechu10 avatar Mar 12 '22 03:03 lukechu10

Sounds good, would you like to PR that (in gloo-net, of course)? This would also require reverting https://github.com/hamza1311/reqwasm/pull/21

ranile avatar Mar 13 '22 16:03 ranile