Skip to content

Instantly share code, notes, and snippets.

@antonu17
Last active February 4, 2020 12:26
Show Gist options
  • Save antonu17/ed6fecf89e1dce6cf36e0e08e6836d6d to your computer and use it in GitHub Desktop.
Save antonu17/ed6fecf89e1dce6cf36e0e08e6836d6d to your computer and use it in GitHub Desktop.
type state struct {
sync.RWMutex
co2 int
temperature float64
}
func (s *state) getCo2() int {
s.RLock()
defer s.RUnlock()
return s.co2
}
func (s *state) setCo2(co2 int) {
s.Lock()
defer s.Unlock()
s.co2 = co2
}
func (s *state) getTemperature() int {
s.RLock()
defer s.RUnlock()
s.temperature
}
func (s *state) setTemperature(temperature int) {
s.Lock()
defer s.Unlock()
s.temperature = temperature
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment