fixes from Jae's review

1. remove pointer
2. add Quit() method to Service interface
This commit is contained in:
Anton Kaliaev
2018-02-12 14:32:09 +04:00
parent f1c8489270
commit 2a24ae90c1
21 changed files with 38 additions and 46 deletions
+1 -1
View File
@@ -338,7 +338,7 @@ func (w *WSEvents) eventListener() {
ch <- result.Data
}
w.mtx.RUnlock()
case <-w.Quit:
case <-w.Quit():
return
}
}
+3 -3
View File
@@ -335,7 +335,7 @@ func (c *WSClient) reconnectRoutine() {
c.startReadWriteRoutines()
}
}
case <-c.Quit:
case <-c.Quit():
return
}
}
@@ -394,7 +394,7 @@ func (c *WSClient) writeRoutine() {
c.Logger.Debug("sent ping")
case <-c.readRoutineQuit:
return
case <-c.Quit:
case <-c.Quit():
if err := c.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")); err != nil {
c.Logger.Error("failed to write message", "err", err)
}
@@ -455,7 +455,7 @@ func (c *WSClient) readRoutine() {
// c.wg.Wait() in c.Stop(). Note we rely on Quit being closed so that it sends unlimited Quit signals to stop
// both readRoutine and writeRoutine
select {
case <-c.Quit:
case <-c.Quit():
case c.ResponsesCh <- response:
}
}
+2 -2
View File
@@ -132,7 +132,7 @@ func TestWSClientReconnectFailure(t *testing.T) {
for {
select {
case <-c.ResponsesCh:
case <-c.Quit:
case <-c.Quit():
return
}
}
@@ -217,7 +217,7 @@ func callWgDoneOnResult(t *testing.T, c *WSClient, wg *sync.WaitGroup) {
if resp.Result != nil {
wg.Done()
}
case <-c.Quit:
case <-c.Quit():
return
}
}
+4 -4
View File
@@ -484,7 +484,7 @@ func (wsc *wsConnection) GetEventSubscriber() types.EventSubscriber {
// It implements WSRPCConnection. It is Goroutine-safe.
func (wsc *wsConnection) WriteRPCResponse(resp types.RPCResponse) {
select {
case <-wsc.Quit:
case <-wsc.Quit():
return
case wsc.writeChan <- resp:
}
@@ -494,7 +494,7 @@ func (wsc *wsConnection) WriteRPCResponse(resp types.RPCResponse) {
// It implements WSRPCConnection. It is Goroutine-safe
func (wsc *wsConnection) TryWriteRPCResponse(resp types.RPCResponse) bool {
select {
case <-wsc.Quit:
case <-wsc.Quit():
return false
case wsc.writeChan <- resp:
return true
@@ -525,7 +525,7 @@ func (wsc *wsConnection) readRoutine() {
for {
select {
case <-wsc.Quit:
case <-wsc.Quit():
return
default:
// reset deadline for every type of message (control or data)
@@ -643,7 +643,7 @@ func (wsc *wsConnection) writeRoutine() {
return
}
}
case <-wsc.Quit:
case <-wsc.Quit():
return
}
}