Skip to content

coder/retry

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

retry

An exponentially backing off retry package for Go.

GoDoc

go get github.com/coder/retry@latest

Features

  • A for loop experience instead of closures
  • Only 3 exported methods
  • No external dependencies

Examples

Wait for connectivity to google.com, checking at most once every second.

func pingGoogle(ctx context.Context) error {
	var err error
	
	for r := retry.New(time.Second, time.Second*10); r.Wait(ctx); {
		_, err = http.Get("https://google.com")
		if err != nil {
			continue
		}
		break
	}
	return err
}

Wait for connectivity to google.com, checking at most 10 times.

func pingGoogle(ctx context.Context) error {
	var err error
	
	for r := retry.New(time.Second, time.Second*10); n := 0; r.Wait(ctx) && n < 10; n++ {
		_, err = http.Get("https://google.com")
		if err != nil {
			continue
		}
		break
	}
	return err
}

About

A tiny retry package for Go.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages