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

Support for contexts #147

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

paulozenida
Copy link

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.

// Check if the context is expired.
select {
default:
case <-ctx.Done():
Copy link

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)
Copy link

Choose a reason for hiding this comment

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

  1. This is breaking change. I doubt it can be accepted.
  2. 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.

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.

None yet

2 participants