Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace goto with for #85

Merged
merged 6 commits into from Apr 7, 2021

Conversation

varas
Copy link
Contributor

@varas varas commented Apr 6, 2021

Replace goto with for as requested #83 (comment)

I still think this is one of the few legit usages of goto, making the code more readable in this case.

wdyt?

publisher/lock/s3_lock.go Outdated Show resolved Hide resolved
@roobre
Copy link
Contributor

roobre commented Apr 6, 2021

I'm personally not a huge fan of goto, I also prefer the for loop. I do think there's a return or break statement missing at the end of the loop tho, when the if branch is no taken.

l.logF("%s attempt %d", l.conf.Owner, tries)
if l.isBusyDeletingExpired() {
l.logF("%s failed, waiting %s", l.conf.Owner, l.conf.RetryBackoff.String())
time.Sleep(l.conf.RetryBackoff)
goto retry
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something to escape the loop is needed if not busy , could be a else+break or something similar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? the for condition will exit the loop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if if l.isBusyDeletingExpired() { is not true i think it should exit the loop and continue with the execution as it was doing with the goto logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true! otherwise in case of long busy it will wait an extra time in the end before exiting

varas and others added 2 commits April 7, 2021 09:22
Co-authored-by: Roberto Santalla <roobre@users.noreply.github.com>
varas and others added 2 commits April 7, 2021 11:35
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
Copy link
Contributor

@gsanchezgavier gsanchezgavier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Comment on lines 96 to 98
if tries >= int(l.conf.MaxRetries) {
break
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this could be removed , the for condition prevents this case

@varas varas merged commit 2473e4c into feat_lock-retry-non-bc Apr 7, 2021
@varas varas deleted the refactor_replace-goto branch April 7, 2021 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants