mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-13 22:51:08 -05:00
Merge pull request #273 from mem/master
Simplify websocket ticker shutdown code
This commit is contained in:
commit
a48ed9a246
1 changed files with 2 additions and 5 deletions
|
@ -172,7 +172,7 @@ func reader(conn *websocket.Conn, stdout io.ReadCloser, stdin io.WriteCloser) {
|
||||||
conn.SetReadDeadline(time.Now().Add(pongWait))
|
conn.SetReadDeadline(time.Now().Add(pongWait))
|
||||||
conn.SetPongHandler(func(string) error { conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
|
conn.SetPongHandler(func(string) error { conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
|
||||||
tickerChan := make(chan bool)
|
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)
|
go ticker(conn, tickerChan)
|
||||||
|
|
||||||
for {
|
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.
|
// between the server and client to keep it alive with ping messages.
|
||||||
func ticker(conn *websocket.Conn, c chan bool) {
|
func ticker(conn *websocket.Conn, c chan bool) {
|
||||||
ticker := time.NewTicker(pingPeriod)
|
ticker := time.NewTicker(pingPeriod)
|
||||||
defer func() {
|
defer ticker.Stop()
|
||||||
ticker.Stop()
|
|
||||||
close(c)
|
|
||||||
}()
|
|
||||||
|
|
||||||
for { // blocking loop with select to wait for stimulation.
|
for { // blocking loop with select to wait for stimulation.
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Reference in a new issue