>
> if `ws.Read` returns after a reasonable timeout, you can perform a
> non-blocking receive on the quit channel to see if it has been
> closed/something has been sent to it:
>
>         select {
>                 case <-quit:
>                         break
>                 default:
>                         // Nothing to do here
>         }
>
>         out, err := ws.Read()
>         /* more stuff in the loop */
>

This is brilliant. I feel bad that I did not think of this myself :-)
Thanks.


>
> Another approach would be to use a websocket library that supports
> passing a context to the Read method (not sure if any of those exists).
> For my usual go-to websocket library (github.com/gorilla/websocket), I
> usually set a read deadline on the connection in cases like this and
> more or less do the nonblocking read as above.
>

Yes, I too use the gorilla websocket library only. I have not touched the
"context" related code as it was not part of the initial release and I
never got around to understanding it. Thanks for the pointer. I will see if
that would help me.

Sankar

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMSEaH67s6nuN7Bnnu4Vz%3DB6YgNyxC%2BcK%2BiVvs9rfyTDwWA4YQ%40mail.gmail.com.

Reply via email to