Skip to content
Merged
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
14 changes: 2 additions & 12 deletions openfeature/event_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openfeature
import (
"fmt"
"log/slog"
"maps"
"slices"
"sync"
"time"
Expand Down Expand Up @@ -229,7 +230,6 @@ func (e *eventExecutor) registerNamedEventingProvider(associatedClient string, p
// startListeningAndShutdownOld is a helper to start concurrent listening to new provider events and invoke shutdown
// hook of the old provider if it's not bound by another subscription
func (e *eventExecutor) startListeningAndShutdownOld(newProvider providerReference, oldReference providerReference) error {

// check if this provider already actively handled - 1:N binding capability
if !isRunning(newProvider, e.activeSubscriptions) {
e.activeSubscriptions = append(e.activeSubscriptions, newProvider)
Expand Down Expand Up @@ -258,7 +258,7 @@ func (e *eventExecutor) startListeningAndShutdownOld(newProvider providerReferen
// shutdown old provider handling

// check if this provider is still bound - 1:N binding capability
if isBound(oldReference, e.defaultProviderReference, mapValues(e.namedProviderReference)) {
if isBound(oldReference, e.defaultProviderReference, slices.Collect(maps.Values(e.namedProviderReference))) {
return nil
}

Expand Down Expand Up @@ -335,7 +335,6 @@ func (e *eventExecutor) triggerEvent(event Event, handler FeatureProvider) {
e.executeHandler(*c, event)
}
}

}

// executeHandler is a helper which performs the actual invocation of the callback
Expand All @@ -358,15 +357,6 @@ func (e *eventExecutor) executeHandler(f func(details EventDetails), event Event
}()
}

// mapValues is a helper until we bump to a go version with maps.Values and slices.Collect
func mapValues[K comparable, V any](m map[K]V) []V {
var values []V
for _, value := range m {
values = append(values, value)
}
return values
}

// isRunning is a helper to check if the given provider is in the given list of providers
func isRunning(provider providerReference, activeProviders []providerReference) bool {
return slices.ContainsFunc(activeProviders, provider.equals)
Expand Down
5 changes: 4 additions & 1 deletion openfeature/openfeature_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openfeature
import (
"errors"
"fmt"
"maps"
"slices"
"sync"

Expand Down Expand Up @@ -232,8 +233,10 @@ func (api *evaluationAPI) initNewAndShutdownOld(clientName string, newProvider F
return nil
}

namedProviders := slices.Collect(maps.Values(api.namedProviders))

// check for multiple bindings
if oldProvider == api.defaultProvider || slices.Contains(mapValues(api.namedProviders), oldProvider) {
if oldProvider == api.defaultProvider || slices.Contains(namedProviders, oldProvider) {
return nil
}

Expand Down
Loading