libkv icon indicating copy to clipboard operation
libkv copied to clipboard

Watch/WatchTree error return is useless, should be changed for an error channel

Open abronan opened this issue 10 years ago • 0 comments

The error return on Watch/WatchTree is virtually useless as we only return (without error) on Get/List failures for etcd and consul. This should be made more consistent across the 3 stores by returning the error through a channel.

Overall, this is an easier pattern to encourage Watches to be resilient to failures:

watchCh, errCh := store.Watch("key", nil)

for {
  select {
    case event := <-watchCh:
      // Do something with the event
    case err := <-errCh:
      // store may be down or an intermittent network issue occured
      log.Error(err)
      // sleep, break or continue
  }
}

abronan avatar Jul 20 '15 22:07 abronan