Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Break the seed retry using the context
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor committed Mar 6, 2020
1 parent 88f3cc8 commit 89576b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions toggle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ func (c *Client) Connect(ctx context.Context) chan error {
c.opts.log.Printf("Error sending the seed flags: %v. Retry in %s", err, retry)
backoff++

time.Sleep(retry)
continue
}

if ctx.Err() != nil {
return
select {
case <-ctx.Done():
return
case <-time.After(retry):
continue
}
}

break
Expand Down
3 changes: 2 additions & 1 deletion toggle/toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ func Initialize(ctx context.Context, name string, opts ...ClientOption) {
DefaultClient = New(name, opts...)
DefaultClient.ParseEnv(os.Environ())

errC := DefaultClient.Connect(ctx)
go func() {
for err := range DefaultClient.Connect(ctx) {
for err := range errC {
DefaultClient.opts.log.Println("Error listening for updates:", err)
}
}()
Expand Down
4 changes: 0 additions & 4 deletions toggle/toggle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestGet(t *testing.T) {
cname string
seed []string
args args
sub bool
want bool
wantRaw string
}{
Expand Down Expand Up @@ -49,9 +48,6 @@ func TestGet(t *testing.T) {

toggle.Initialize(ctx, tt.cname)

if tt.sub {
toggle.DefaultClient = toggle.New(tt.cname)
}
if got := toggle.Get(tt.args.name, tt.args.opts...); got != tt.want {
t.Errorf("Get() = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 89576b8

Please sign in to comment.