if err := ws.WriteControl(Ping...); err != nil {
handle error
}
}
-----
ws.SetPongHandler(func(string) error { return ws.SetReadDeadline(time.Now().Add(pingInterval + slop)) })
for {
if _, _, err := ws.NextReader(); err != nil {
handle error
}
}
There are two reasons why I used callbacks to handle control messages. The first is that callbacks avoid the need to buffer control messages. The second is that it's easier to write functions like ReadJSON when control messages are handled separately from data messages.
The proposed feature does fit with the existing API. I will accept a pull request for the feature.