Skip to content

Commit 403778c

Browse files
committed
CR suggestion
Signed-off-by: Uri Sternik <uri.sternik@wiz.io>
1 parent 1a931be commit 403778c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

cmd/config-manager/main.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ type Flags struct {
7979
// Multiple calls to Set() do not queue, meaning that only calls to Get() made
8080
// *before* a call to Set() will be notified.
8181
type SyncableConfig struct {
82-
cond *sync.Cond
83-
mutex sync.Mutex
84-
current string
85-
lastRead string
86-
initialized bool
82+
cond *sync.Cond
83+
mutex sync.Mutex
84+
current string
85+
lastRead *string
8786
}
8887

8988
// NewSyncableConfig creates a new SyncableConfig
@@ -107,12 +106,12 @@ func (m *SyncableConfig) Set(value string) {
107106
func (m *SyncableConfig) Get() string {
108107
m.mutex.Lock()
109108
defer m.mutex.Unlock()
110-
if m.initialized && m.lastRead == m.current {
109+
if m.lastRead != nil && *m.lastRead == m.current {
111110
m.cond.Wait()
112111
}
113-
m.initialized = true
114-
m.lastRead = m.current
115-
return m.lastRead
112+
val := m.current
113+
m.lastRead = &val
114+
return *m.lastRead
116115
}
117116

118117
func main() {

0 commit comments

Comments
 (0)