diff --git a/bindings/client.go b/bindings/client.go index 2ebc43897cf4daa64f420a1831167cd746ff22b8..391aa361c6da731a19d2647d6d3aacd003e70208 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -36,7 +36,6 @@ func init() { // to support the gomobile Client interface type Client struct { api api.Client - waitForNetwork chan bool } // NewClient creates client storage, generates keys, connects, and registers @@ -225,41 +224,15 @@ func (c *Client) StopNetworkFollower(timeoutMS int) error { // WaitForNewtwork will block until either the network is healthy or the // passed timeout. It will return true if the network is healthy func (c *Client) WaitForNetwork(timeoutMS int) bool { - timeout := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond) - if c.waitForNetwork == nil{ - c.waitForNetwork = make(chan bool, 1) - c.api.GetHealth().AddChannel(c.waitForNetwork) - } - - //flush the channel if it is already full - select{ - case <- c.waitForNetwork: - default: - } - - // start a thread to check if healthy in a second in order to handle - // race conditions - go func() { - time.Sleep(1*time.Second) - if c.api.GetHealth().IsHealthy() { - select{ - case c.waitForNetwork<-true: - default: - } - } - }() - - //wait for network to be healthy or the timer to time out - for { - select{ - case result := <- c.waitForNetwork: - if result { - return true - } - case <-timeout.C: - return false + start := time.Now() + timeout := time.Duration(timeoutMS)*time.Millisecond + for time.Now().Sub(start)<timeout{ + if c.api.GetHealth().IsHealthy(){ + return true } + time.Sleep(250*time.Millisecond) } + return false } // Gets the state of the network follower. Returns: diff --git a/network/health/tracker.go b/network/health/tracker.go index 7779a86b96502c2d34a17690e26c79c46bcdad8b..ff53904f2015fe81af4938efd9ca8222fd68eba1 100644 --- a/network/health/tracker.go +++ b/network/health/tracker.go @@ -159,7 +159,7 @@ func (t *Tracker) transmit(health bool) { select { case c <- health: default: - jww.WARN.Printf("Unable to send Health event") + jww.DEBUG.Printf("Unable to send Health event") } }