Skip to content

Commit

Permalink
remove errgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong committed Nov 12, 2023
1 parent 323280f commit c67e064
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
21 changes: 0 additions & 21 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"

"github.com/ktong/konf"
)
Expand Down Expand Up @@ -179,26 +178,6 @@ func TestConfig_Watch(t *testing.T) {
require.Equal(t, "changed", cfg)
}

func TestConfig_Watch_twice(t *testing.T) {
t.Parallel()

config, err := konf.New(konf.WithLoader(mapWatcher(make(chan map[string]any))))
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

group, ctx := errgroup.WithContext(ctx)
group.Go(func() error {
return config.Watch(ctx)
})
group.Go(func() error {
return config.Watch(ctx)
})

require.EqualError(t, group.Wait(), "[konf] Watch only can be called once")
}

type mapWatcher chan map[string]any

func (m mapWatcher) Load() (map[string]any, error) {
Expand Down
22 changes: 10 additions & 12 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"context"
"embed"
"fmt"
"sync"
"time"

"golang.org/x/sync/errgroup"

"github.com/ktong/konf"
"github.com/ktong/konf/provider/env"
"github.com/ktong/konf/provider/file"
Expand Down Expand Up @@ -48,17 +47,16 @@ func ExampleWatch() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

group, ctx := errgroup.WithContext(ctx)
group.Go(func() error {
return konf.Watch(ctx, func() {
var waitGroup sync.WaitGroup
waitGroup.Add(1)
go func() {
if err := konf.Watch(ctx, func() {
fmt.Print(konf.Get[string]("server.host"))
})
})

if err := group.Wait(); err != nil {
// Handle error here.
panic(err)
}
}); err != nil {
panic(err)
}
}()
waitGroup.Wait()
// Output:
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
require ( // for test
github.com/stretchr/testify v1.8.4
go.uber.org/goleak v1.3.0
golang.org/x/sync v0.5.0
)

require ( // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand All @@ -14,11 +15,10 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit c67e064

Please sign in to comment.