rewrite ws client to expose a callback instead of a channel

callback gives more power to the publisher. plus it is optional
comparing to a channel, which will block the whole client if you won't
read from it.
This commit is contained in:
Anton Kaliaev
2017-09-29 14:11:46 +04:00
committed by Zach Ramsay
parent ce36a0111a
commit 45ff7cdd0c
3 changed files with 19 additions and 10 deletions

View File

@ -226,7 +226,9 @@ func (w *WSEvents) Start() (bool, error) {
st, err := w.EventSwitch.Start()
// if we did start, then OnStart here...
if st && err == nil {
ws := rpcclient.NewWSClient(w.remote, w.endpoint)
ws := rpcclient.NewWSClient(w.remote, w.endpoint, rpcclient.OnReconnect(func() {
w.redoSubscriptions()
}))
_, err = ws.Start()
if err == nil {
w.ws = ws
@ -335,8 +337,6 @@ func (w *WSEvents) eventListener() {
// before cleaning up the w.ws stuff
w.done <- true
return
case <-w.ws.ReconnectCh:
w.redoSubscriptions()
}
}
}