Created
January 26, 2019 09:55
-
-
Save heppu/6b655d79b5838bb4f3d615e78d84a994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Storage interface { | |
Add(key, val string) | |
} | |
type SafeStorage struct { | |
storageMu *sync.Mutex | |
storage Storage | |
} | |
func NewSafeStorage(storage Storage) *SafeStorage { | |
return &SafeStorage{ | |
storageMu: &sync.Mutex{}, | |
storage: storage, | |
} | |
} | |
func (s *SafeStorage) Add(key, val string) { | |
s.storageMu.Lock() | |
s.storage.Add(key, val) | |
s.storageMu.Unlock() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment