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 {
|
func NewWSClient(remoteAddr, endpoint string) *WSClient {
|
||||||
addr, dialer := makeHTTPDialer(remoteAddr)
|
addr, dialer := makeHTTPDialer(remoteAddr)
|
||||||
wsClient := &WSClient{
|
wsClient := &WSClient{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Dialer: dialer,
|
Dialer: dialer,
|
||||||
Endpoint: endpoint,
|
Endpoint: endpoint,
|
||||||
Conn: nil,
|
Conn: nil,
|
||||||
ResultsCh: make(chan json.RawMessage, wsResultsChannelCapacity),
|
|
||||||
ErrorsCh: make(chan error, wsErrorsChannelCapacity),
|
|
||||||
}
|
}
|
||||||
wsClient.BaseService = *cmn.NewBaseService(log, "WSClient", wsClient)
|
wsClient.BaseService = *cmn.NewBaseService(log, "WSClient", wsClient)
|
||||||
return wsClient
|
return wsClient
|
||||||
|
@ -48,16 +46,24 @@ func (wsc *WSClient) String() string {
|
||||||
return wsc.Address + ", " + wsc.Endpoint
|
return wsc.Address + ", " + wsc.Endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnStart implements cmn.BaseService interface
|
||||||
func (wsc *WSClient) OnStart() error {
|
func (wsc *WSClient) OnStart() error {
|
||||||
wsc.BaseService.OnStart()
|
wsc.BaseService.OnStart()
|
||||||
err := wsc.dial()
|
err := wsc.dial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
wsc.ResultsCh = make(chan json.RawMessage, wsResultsChannelCapacity)
|
||||||
|
wsc.ErrorsCh = make(chan error, wsErrorsChannelCapacity)
|
||||||
go wsc.receiveEventsRoutine()
|
go wsc.receiveEventsRoutine()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnReset implements cmn.BaseService interface
|
||||||
|
func (wsc *WSClient) OnReset() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (wsc *WSClient) dial() error {
|
func (wsc *WSClient) dial() error {
|
||||||
|
|
||||||
// Dial
|
// Dial
|
||||||
|
@ -84,6 +90,7 @@ func (wsc *WSClient) dial() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnStop implements cmn.BaseService interface
|
||||||
func (wsc *WSClient) OnStop() {
|
func (wsc *WSClient) OnStop() {
|
||||||
wsc.BaseService.OnStop()
|
wsc.BaseService.OnStop()
|
||||||
wsc.Conn.Close()
|
wsc.Conn.Close()
|
||||||
|
|
Loading…
Reference in New Issue