File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "sync"
45 "time"
56
67 "github.com/google/uuid"
@@ -24,19 +25,27 @@ type current struct {
2425// inMemoryCurrentStore stores point current values in a local in-memory cache.
2526// These are not shared between instances.
2627type inMemoryCurrentStore struct {
28+ mux * sync.Mutex
2729 cache map [uuid.UUID ]current
2830}
2931
3032func newInMemoryCurrentStore () inMemoryCurrentStore {
31- return inMemoryCurrentStore {cache : map [uuid.UUID ]current {}}
33+ return inMemoryCurrentStore {
34+ mux : & sync.Mutex {},
35+ cache : map [uuid.UUID ]current {},
36+ }
3237}
3338
3439func (s inMemoryCurrentStore ) getCurrent (id uuid.UUID ) current {
40+ s .mux .Lock ()
41+ defer s .mux .Unlock ()
3542 return s .cache [id ]
3643}
3744
3845func (s inMemoryCurrentStore ) setCurrent (id uuid.UUID , input currentInput ) {
3946 timestamp := time .Now ()
47+ s .mux .Lock ()
48+ defer s .mux .Unlock ()
4049 s .cache [id ] = current {
4150 Ts : & timestamp ,
4251 Value : input .Value ,
You can’t perform that action at this time.
0 commit comments