MCPcopy
hub / github.com/redis/go-redis / eventually

Function eventually

main_test.go:271–309  ·  view source on GitHub ↗
(fn func() error, timeout time.Duration)

Source from the content-addressed store, hash-verified

269}
270
271func eventually(fn func() error, timeout time.Duration) error {
272 errCh := make(chan error, 1)
273 done := make(chan struct{})
274 exit := make(chan struct{})
275
276 go func() {
277 for {
278 err := fn()
279 if err == nil {
280 close(done)
281 return
282 }
283
284 select {
285 case errCh <- err:
286 default:
287 }
288
289 select {
290 case <-exit:
291 return
292 case <-time.After(timeout / 100):
293 }
294 }
295 }()
296
297 select {
298 case <-done:
299 return nil
300 case <-time.After(timeout):
301 close(exit)
302 select {
303 case err := <-errCh:
304 return err
305 default:
306 return fmt.Errorf("timeout after %s without an error", timeout)
307 }
308 }
309}
310
311func connectTo(port string) (*redis.Client, error) {
312 client := redis.NewClient(&redis.Options{

Callers 4

newClusterClientMethod · 0.85
configureClusterTopologyFunction · 0.85
connectToFunction · 0.85
initializeTLSClusterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected