Since read and send messages are in different functions/goroutines, when an error occurs, how can they be synchronized?
Suppose I set up a listen goroutine by this function below, with `conn` as a global variable of the connection: func listen(){ for{ _, message, err := conn.ReadMessage() if err != nil{ break }else{ //analyze the message fmt.Println(string(message)) } conn.close() } Of course, I have the close function and send function: func (c *Conn) close(){ if c != nil{ c.Close() c = nil } } func (c *Conn) send(){ err=c.WriteMessage(websocket.TextMessage, data) if err != nil{ c.close() } } This brings up the synchronization problem: An connection error could occur in either occasion, and a new connection could be coming in. Therefore is there an implied synchronization in the connection? For example, as the err by `c.WriteMessage` occurs, the `conn.ReadMessage()` would raise out an error, so the goroutine on `listen` would close by itself. Or, if the `conn.close()` gets called, and `c.close()` gets executed, the ` conn.ReadMessage()` would raise out an error, so the goroutine on `listen` would close by itself. If either of the above is true, I call the disconnection synchronization solid. Otherwise, I am worried that `conn.ReadMessage()` would wait for too long (even indefinitely), or `conn=nil` could raise panic? Thanks for your read, and what is your thought? Zhaoxun -- 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/60678153-8b44-436c-a5c5-a1cb58bdc2c6n%40googlegroups.com.