Created
January 5, 2023 22:11
-
-
Save reetasingh/2ef502df00b1e6db5fc8fcfbfb3bd46e to your computer and use it in GitHub Desktop.
using retry with decorator and same interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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