Skip to content

Add DoInAttemptWithDelay and DoInAttempt functions#450

Open
marktiro wants to merge 1 commit intosamber:masterfrom
marktiro:do-attempt
Open

Add DoInAttemptWithDelay and DoInAttempt functions#450
marktiro wants to merge 1 commit intosamber:masterfrom
marktiro:do-attempt

Conversation

@marktiro
Copy link
Copy Markdown

@marktiro marktiro commented May 11, 2024

The Attempt like functions are awesome and help a lot with operations prone to fail, i.e. networking stuff.

Nevertheless, only procedure implementation is available in the library. So, it forced me to use constructions like the following:

fooOut, err := func() (FooOut, error) {
	var fooOut FooOut
	var err error
	_, _ = Attempt(10, func(_ int) error {
		fooOut, err = foo()
		return err
	})
	return fooOut, err
}()

I ended up doing this stuff so often, so I decided to contribute if you do not mind :)

@samber
Copy link
Copy Markdown
Owner

samber commented Jun 28, 2024

Why not just implement Attempt0, Attempt1, Attempt2 ... AttemptX ?

@marktiro
Copy link
Copy Markdown
Author

Why not just implement Attempt0, Attempt1, Attempt2 ... AttemptX ?

it's been a while since your reply 😄

Actually, you are completely right, I will rewrite the functions to ones with numbers at the end 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants