Co-authored-by: Hao Duan <duan.hao@hyperchain.cn>
This commit is contained in:
parent
d02301f758
commit
a188a1e150
@ -154,7 +154,7 @@ func (s *Service) loop() {
|
|||||||
txSub := txpool.SubscribeNewTxsEvent(txEventCh)
|
txSub := txpool.SubscribeNewTxsEvent(txEventCh)
|
||||||
defer txSub.Unsubscribe()
|
defer txSub.Unsubscribe()
|
||||||
|
|
||||||
// Start a goroutine that exhausts the subsciptions to avoid events piling up
|
// Start a goroutine that exhausts the subscriptions to avoid events piling up
|
||||||
var (
|
var (
|
||||||
quitCh = make(chan struct{})
|
quitCh = make(chan struct{})
|
||||||
headCh = make(chan *types.Block, 1)
|
headCh = make(chan *types.Block, 1)
|
||||||
@ -194,8 +194,7 @@ func (s *Service) loop() {
|
|||||||
}
|
}
|
||||||
close(quitCh)
|
close(quitCh)
|
||||||
}()
|
}()
|
||||||
// Loop reporting until termination
|
|
||||||
for {
|
|
||||||
// Resolve the URL, defaulting to TLS, but falling back to none too
|
// Resolve the URL, defaulting to TLS, but falling back to none too
|
||||||
path := fmt.Sprintf("%s/api", s.host)
|
path := fmt.Sprintf("%s/api", s.host)
|
||||||
urls := []string{path}
|
urls := []string{path}
|
||||||
@ -204,6 +203,8 @@ func (s *Service) loop() {
|
|||||||
if !strings.Contains(path, "://") {
|
if !strings.Contains(path, "://") {
|
||||||
urls = []string{"wss://" + path, "ws://" + path}
|
urls = []string{"wss://" + path, "ws://" + path}
|
||||||
}
|
}
|
||||||
|
// Loop reporting until termination
|
||||||
|
for {
|
||||||
// Establish a websocket connection to the server on any supported URL
|
// Establish a websocket connection to the server on any supported URL
|
||||||
var (
|
var (
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
@ -240,11 +241,12 @@ func (s *Service) loop() {
|
|||||||
}
|
}
|
||||||
// Keep sending status updates until the connection breaks
|
// Keep sending status updates until the connection breaks
|
||||||
fullReport := time.NewTicker(15 * time.Second)
|
fullReport := time.NewTicker(15 * time.Second)
|
||||||
defer fullReport.Stop()
|
|
||||||
|
|
||||||
for err == nil {
|
for err == nil {
|
||||||
select {
|
select {
|
||||||
case <-quitCh:
|
case <-quitCh:
|
||||||
|
fullReport.Stop()
|
||||||
|
// Make sure the connection is closed
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -269,6 +271,7 @@ func (s *Service) loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fullReport.Stop()
|
||||||
// Make sure the connection is closed
|
// Make sure the connection is closed
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user