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

Code simplification #2516

Merged
merged 1 commit into from
Dec 6, 2017
Merged

Code simplification #2516

merged 1 commit into from
Dec 6, 2017

Conversation

ferhatelmas
Copy link
Contributor

@ferhatelmas ferhatelmas commented Dec 4, 2017

What does this PR do?

Does some simplification.

Motivation

Makes code easier to understand since uses less tokens.

More

  • Added/updated tests (One small change touches tests)

Additional Notes

  • drop select with only one case

return
}
for range stop {
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, is this really exactly equivalent for the case where the channel gets closed? Doesn't the old version still call cancel() while the new one doesn't anymore?

Also, couldn't we just do

<-stop
cancel()

as we immediately return anyway when the channel fires?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding here was that we need to cancel if we take stop. Refactoring should be keeping semantics.

Only <-stop will call anyway so it's wrong to me.

Copy link
Contributor

@timoreimann timoreimann Dec 4, 2017

Choose a reason for hiding this comment

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

Inside the goroutine, we select on the stop channel without any other select case available. That means we can only ever escape the select when the stop channel fires (either through a message or a close). Once it does, we invoke cancel and return immediately, giving us zero chance to have another for loop iteration that could process any further events from the stop channel (which makes total sense as we want to process the stop signal exactly once).

I think my simplification suggestion does effectively the same, using just fewer keywords: wait for a channel event; call cancel; and then return (implicitly). Please let me know where you see the semantical difference.

Should be good though to have another pair of eyes on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it was different from other cases bottom, I thought intention was to call only on getting something on channel. Otherwise, semantic will be kept same with just <-stop and actually putting for range won't call cancel if we just close channel. Updating this part and rebasing as requested by @ldez.

@ldez
Copy link
Contributor

ldez commented Dec 5, 2017

@ferhatelmas could you rebase ?

@ferhatelmas
Copy link
Contributor Author

@timoreimann @ldez rebased and diff got even smaller 😄

 - drop `select` with only one `case`
@ferhatelmas
Copy link
Contributor Author

Updated additional notes to reflect last status.

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks. 👏

Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

@ldez ldez modified the milestones: 1.5, 1.6 Dec 6, 2017
@traefiker traefiker merged commit 6890dc1 into traefik:master Dec 6, 2017
@ldez ldez changed the title Simplification Code simplification Jan 7, 2018
@ldez ldez removed area/provider kind/enhancement a new or improved feature. labels Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants