Skip to content
Permalink
Browse files

Wait for goroutines to finnish on connection close

  • Loading branch information...
jezek committed Mar 15, 2018
1 parent 63b50f5 commit 6a08d199403e4168a450e6e08eacf4b5e041ef16
Showing with 193 additions and 114 deletions.
  1. +8 −0 cookie.go
  2. +185 −114 xgb.go
@@ -76,6 +76,8 @@ func (c Cookie) Reply() ([]byte, error) {
return c.replyUnchecked()
}

var errConnectionClosed = errors.New("connection was closed")

// replyChecked waits for a response on either the replyChan or errorChan
// channels. If the former arrives, the bytes are returned with a nil error.
// If the latter arrives, no bytes are returned (nil) and the error received
@@ -98,6 +100,8 @@ func (c Cookie) replyChecked() ([]byte, error) {
return reply, nil
case err := <-c.errorChan:
return nil, err
case <-c.conn.done:
return nil, errConnectionClosed
}
}

@@ -121,6 +125,8 @@ func (c Cookie) replyUnchecked() ([]byte, error) {
return reply, nil
case <-c.pingChan:
return nil, nil
case <-c.conn.done:
return nil, errConnectionClosed
}
}

@@ -161,5 +167,7 @@ func (c Cookie) Check() error {
return err
case <-c.pingChan:
return nil
case <-c.conn.done:
return errConnectionClosed
}
}
Oops, something went wrong.

0 comments on commit 6a08d19

Please sign in to comment.
You can’t perform that action at this time.