ソースを参照

Restructured ringDescriber run for loop

Zach Badgett 10 年 前
コミット
d10a9293ed
1 ファイル変更14 行追加16 行削除
  1. 14 16
      host_source.go

+ 14 - 16
host_source.go

@@ -97,23 +97,21 @@ func (h *ringDescriber) run(sleep time.Duration) {
 	}
 
 	for {
-		// if we have 0 hosts this will return the previous list of hosts to
-		// attempt to reconnect to the cluster otherwise we would never find
-		// downed hosts again, could possibly have an optimisation to only
-		// try to add new hosts if GetHosts didnt error and the hosts didnt change.
-		hosts, partitioner, err := h.GetHosts()
-		if err != nil {
-			log.Println("RingDescriber: unable to get ring topology:", err)
-		} else {
-			h.session.Pool.SetHosts(hosts)
-			if v, ok := h.session.Pool.(SetPartitioner); ok {
-				v.SetPartitioner(partitioner)
-			}
-		}
-
-		time.Sleep(sleep)
-
 		select {
+		case <-time.After(sleep):
+			// if we have 0 hosts this will return the previous list of hosts to
+			// attempt to reconnect to the cluster otherwise we would never find
+			// downed hosts again, could possibly have an optimisation to only
+			// try to add new hosts if GetHosts didnt error and the hosts didnt change.
+			hosts, partitioner, err := h.GetHosts()
+			if err != nil {
+				log.Println("RingDescriber: unable to get ring topology:", err)
+			} else {
+				h.session.Pool.SetHosts(hosts)
+				if v, ok := h.session.Pool.(SetPartitioner); ok {
+					v.SetPartitioner(partitioner)
+				}
+			}
 		case <-h.closeChan:
 			return
 		}