-
Notifications
You must be signed in to change notification settings - Fork 459
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
Support for contexts #147
base: master
Are you sure you want to change the base?
Support for contexts #147
Conversation
// Check if the context is expired. | ||
select { | ||
default: | ||
case <-ctx.Done(): |
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.
This looks a bit useless. At this point there is no network call yet. Dial happens below in c.dial. You want to extend dial with custom dialer, see https://pkg.go.dev/net#Dialer.DialContext
@@ -31,8 +32,8 @@ import ( | |||
type ServerSelector interface { | |||
// PickServer returns the server address that a given item | |||
// should be shared onto. | |||
PickServer(key string) (net.Addr, error) | |||
Each(func(net.Addr) error) error | |||
PickServer(ctx context.Context, key string) (net.Addr, error) |
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.
- This is breaking change. I doubt it can be accepted.
- Wonder what is the use case to add context for these methods. You can have background goroutine which updates servers list if needed. Current implementation also indicates that context is not needed.
This MR, which pretty much adds contexts to all exported methods, allows us to use that information not only in the main library component but also in custom server list, which then can be used for other stuff such as instrumentation for new relic, which was the original objective for which I forked the library.