Browse Source

Merge pull request #13 from tendermint/allow-for-multiple-restarts

[WSClient] allow for multiple restarts
pull/456/head
Ethan Buchman 8 years ago
committed by GitHub
parent
commit
4671c44b2d
1 changed files with 13 additions and 6 deletions
  1. +13
    -6
      client/ws_client.go

+ 13
- 6
client/ws_client.go View File

@ -33,12 +33,10 @@ type WSClient struct {
func NewWSClient(remoteAddr, endpoint string) *WSClient {
addr, dialer := makeHTTPDialer(remoteAddr)
wsClient := &WSClient{
Address: addr,
Dialer: dialer,
Endpoint: endpoint,
Conn: nil,
ResultsCh: make(chan json.RawMessage, wsResultsChannelCapacity),
ErrorsCh: make(chan error, wsErrorsChannelCapacity),
Address: addr,
Dialer: dialer,
Endpoint: endpoint,
Conn: nil,
}
wsClient.BaseService = *cmn.NewBaseService(log, "WSClient", wsClient)
return wsClient
@ -48,16 +46,24 @@ func (wsc *WSClient) String() string {
return wsc.Address + ", " + wsc.Endpoint
}
// OnStart implements cmn.BaseService interface
func (wsc *WSClient) OnStart() error {
wsc.BaseService.OnStart()
err := wsc.dial()
if err != nil {
return err
}
wsc.ResultsCh = make(chan json.RawMessage, wsResultsChannelCapacity)
wsc.ErrorsCh = make(chan error, wsErrorsChannelCapacity)
go wsc.receiveEventsRoutine()
return nil
}
// OnReset implements cmn.BaseService interface
func (wsc *WSClient) OnReset() error {
return nil
}
func (wsc *WSClient) dial() error {
// Dial
@ -84,6 +90,7 @@ func (wsc *WSClient) dial() error {
return nil
}
// OnStop implements cmn.BaseService interface
func (wsc *WSClient) OnStop() {
wsc.BaseService.OnStop()
wsc.Conn.Close()


Loading…
Cancel
Save