Skip to content

Instantly share code, notes, and snippets.

@heppu
Created January 26, 2019 09:55
Show Gist options
  • Save heppu/6b655d79b5838bb4f3d615e78d84a994 to your computer and use it in GitHub Desktop.
Save heppu/6b655d79b5838bb4f3d615e78d84a994 to your computer and use it in GitHub Desktop.
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