Skip to content

Commit

Permalink
Remove onconfigchange params
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Jan 30, 2020
1 parent d092aef commit c179fc9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions auto_polling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ type autoPollingPolicy struct {
initialized uint32
stop chan struct{}
closed uint32
configChanged func(config string, parser *ConfigParser)
parser *ConfigParser
configChanged func()
}

// autoPollConfig describes the configuration for auto polling.
type autoPollConfig struct {
// The auto polling interval.
autoPollInterval time.Duration
// The configuration change listener.
changeListener func(config string, parser *ConfigParser)
changeListener func()
}

func (config autoPollConfig) getModeIdentifier() string {
Expand All @@ -41,7 +40,7 @@ func AutoPoll(interval time.Duration) RefreshMode {
// AutoPollWithChangeListener creates an auto polling refresh mode with change listener callback.
func AutoPollWithChangeListener(
interval time.Duration,
changeListener func(config string, parser *ConfigParser)) RefreshMode {
changeListener func()) RefreshMode {
return autoPollConfig{autoPollInterval: interval, changeListener: changeListener}
}

Expand All @@ -58,7 +57,6 @@ func newAutoPollingPolicy(
initialized: no,
stop: make(chan struct{}),
configChanged: autoPollConfig.changeListener,
parser: newParser(logger),
}
policy.startPolling()
return policy
Expand Down Expand Up @@ -109,7 +107,7 @@ func (policy *autoPollingPolicy) poll() {
if response.isFetched() && cached != response.body {
policy.store.set(response.body)
if policy.configChanged != nil {
policy.configChanged(response.body, policy.parser)
policy.configChanged()
}
}

Expand Down
8 changes: 4 additions & 4 deletions auto_polling_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ func TestAutoPollingPolicy_GetConfigurationAsync_WithListener(t *testing.T) {
fetcher := newFakeConfigProvider()
logger := DefaultLogger()
fetcher.SetResponse(fetchResponse{status: Fetched, body: "test"})
c := make(chan string, 1)
c := make(chan bool, 1)
defer close(c)
policy := newAutoPollingPolicy(
fetcher,
newConfigStore(logger, newInMemoryConfigCache()),
logger,
AutoPollWithChangeListener(
time.Second*2,
func(config string, parser *ConfigParser) { c <- config },
func() { c <- true },
).(autoPollConfig),
)
defer policy.close()
config := <-c
called := <-c

if config != "test" {
if !called {
t.Error("Expecting test as result")
}
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package configcat

const (
version = "3.0"
version = "3.1"
)

0 comments on commit c179fc9

Please sign in to comment.