ws-rs icon indicating copy to clipboard operation
ws-rs copied to clipboard

Establishing connection and message handling loop should be callable separately

Open Sushisource opened this issue 5 years ago • 2 comments

ws::connect blocks indefinitely if it works, but returns an error immediately if establishing the connection fails.

If you are creating a thread and connecting inside it, you'd very often like to have the function that does that return immediately with an error if the host is missing, the url is invalid, etc etc. However in order to do that with the current API, you have to (and please let me know if I'm wrong) play some dirty games by doing something like (this is how I'm solving the problem currently) creating a fake no-op Handler that finishes the event loop immediately, so you can connect with that to see if the connection works, then spawn your real handler. My first solution involved playing games with timing out joining the thread.

Having to do this sort of workaround is kinda painful.

Thanks for the great library!

Sushisource avatar May 21 '19 21:05 Sushisource