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

Add ConnectWithContext method #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func ConnectWithDialer(servers []string, sessionTimeout time.Duration, dialer Di
// server and keep the same session. This is means any ephemeral nodes and
// watches are maintained.
func Connect(servers []string, sessionTimeout time.Duration, options ...connOption) (*Conn, <-chan Event, error) {
return ConnectWithContext(context.Background(), servers, sessionTimeout, options...)
}

// ConnectWithContext is the same as Connect (above) but includes a context parameter
func ConnectWithContext(ctx context.Context, servers []string, sessionTimeout time.Duration, options ...connOption) (*Conn, <-chan Event, error) {
if len(servers) == 0 {
return nil, nil, errors.New("zk: server list must not be empty")
}
Expand Down Expand Up @@ -217,8 +222,6 @@ func Connect(servers []string, sessionTimeout time.Duration, options ...connOpti
}

conn.setTimeouts(int32(sessionTimeout / time.Millisecond))
// TODO: This context should be passed in by the caller to be the connection lifecycle context.
ctx := context.Background()

go func() {
conn.loop(ctx)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
module github.com/go-zookeeper/zk

module github.com/test/zk

Choose a reason for hiding this comment

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

can you revert this modification?

go 1.13