reqwasm
reqwasm copied to clipboard
Implement `Clone` for `WebSocket`
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.
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
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.
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