Commit a48ed9a2 authored by Austin Cherry's avatar Austin Cherry

Merge pull request #273 from mem/master

Simplify websocket ticker shutdown code
parents b713a779 d4a14af1
......@@ -172,7 +172,7 @@ func reader(conn *websocket.Conn, stdout io.ReadCloser, stdin io.WriteCloser) {
conn.SetReadDeadline(time.Now().Add(pongWait))
conn.SetPongHandler(func(string) error { conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
tickerChan := make(chan bool)
defer func() { tickerChan <- true }() // make sure to close the ticker when we are done.
defer close(tickerChan) // make sure to close the ticker when we are done.
go ticker(conn, tickerChan)
for {
......@@ -213,10 +213,7 @@ func reader(conn *websocket.Conn, stdout io.ReadCloser, stdin io.WriteCloser) {
// between the server and client to keep it alive with ping messages.
func ticker(conn *websocket.Conn, c chan bool) {
ticker := time.NewTicker(pingPeriod)
defer func() {
ticker.Stop()
close(c)
}()
defer ticker.Stop()
for { // blocking loop with select to wait for stimulation.
select {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment