Merge pull request #13 from tendermint/allow-for-multiple-restarts
[WSClient] allow for multiple restarts
This commit is contained in:
commit
4671c44b2d
|
@ -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…
Reference in New Issue