Skip to content

Instantly share code, notes, and snippets.

@reetasingh
Created January 5, 2023 22:11
Show Gist options
  • Save reetasingh/2ef502df00b1e6db5fc8fcfbfb3bd46e to your computer and use it in GitHub Desktop.
Save reetasingh/2ef502df00b1e6db5fc8fcfbfb3bd46e to your computer and use it in GitHub Desktop.
using retry with decorator and same interface
type ReaderRetryDecorator struct {
retryAttempts int
reader IReader
}
func (d ReaderRetryDecorator) Read() error {
var err error
for i := 0; i < d.retryAttempts; i++ {
err := d.reader.Read()
if err == nil {
return nil
}
}
return err
}
func main() {
retryReader := ReaderRetryDecorator{3, Reader{}}
retryReader.Read()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment