-
Notifications
You must be signed in to change notification settings - Fork 712
refactor: reduce context.Background() #3888
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
base: master
Are you sure you want to change the base?
Conversation
d321bbf to
1566004
Compare
cmd/limactl/clone.go
Outdated
| return err | ||
| } | ||
| yBytes, err := yqutil.EvaluateExpression(yq, yContent) | ||
| yBytes, err := yqutil.EvaluateExpression(cmd.Context(), yq, yContent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| yBytes, err := yqutil.EvaluateExpression(cmd.Context(), yq, yContent) | |
| yBytes, err := yqutil.EvaluateExpression(ctx, yq, yContent) |
Same for other occurrences of cmd.Context() too
1566004 to
5426244
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
I have only 2 stylistic nit-picks that you can address, if you want. But we already have existing functions that use _ for the single unnamed parameter, so it isn't a new issue.
There is of course the issue of failing CI, but I think this might be GitHub flakiness; we'll see...
pkg/driver/driver.go
Outdated
| type GuestAgent interface { | ||
| // ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent. | ||
| ForwardGuestAgent() bool | ||
| ForwardGuestAgent(_ context.Context) bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a function/method has only unnamed parameters, then you don't need to specify the _ name. It is only needed when you want to provide a name for parameters with a basic type like bool. int, or string, which are not self-explanatory because you cannot mix named and unnamed parameters.
| ForwardGuestAgent(_ context.Context) bool | |
| ForwardGuestAgent(context.Context) bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we raise a new Issue/PR focusing on removing _ for single unnamed parameter to make it consistent?
pkg/hostagent/hostagent.go
Outdated
| remoteUnix := "/run/lima-guestagent.sock" | ||
|
|
||
| a.onClose = append(a.onClose, func() error { | ||
| ctxBG := context.Background() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a premature optimization. You introduce an extra variable name that the user needs to keep track of instead of calling a very cheap function multiple times.
It doesn't matter much, but I would always try to minimize the context that the developer needs to carry in their head while reading the code, especially if it is a rather long function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense—I'll drop ctxBG and just call context.Background() directly.
5426244 to
6a5b683
Compare
|
@ashwat287, please fix the merge conflicts |
b9c9050 to
fffdae1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in the pkg/hostagent/dns/dns.go might be the reason for CI failures
pkg/hostagent/dns/dns.go
Outdated
| type DNSHandler interface { | ||
| ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) | ||
| } | ||
|
|
||
| type DNSServer struct { | ||
| Server dns.Server | ||
| DNSHandler DNSHandler | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? This seems out of context for this PR
fffdae1 to
75692e7
Compare
Signed-off-by: nerdylucifer <ashwatpas@gmail.com>
75692e7 to
79954fd
Compare
fixes #3875