refactor singleton

pull/231/head
Minh Doan 6 years ago
parent a0f550b922
commit ec5c0495c9
  1. 10
      internal/utils/singleton.go

@ -14,19 +14,19 @@ type UniqueValidatorID struct {
uniqueID uint32 uniqueID uint32
} }
var instance *UniqueValidatorID var validatorIDInstance *UniqueValidatorID
var logInstance log.Logger var logInstance log.Logger
var once sync.Once var onceForUniqueValidatorID sync.Once
var onceForLog sync.Once var onceForLog sync.Once
// GetUniqueValidatorIDInstance returns a singleton instance // GetUniqueValidatorIDInstance returns a singleton instance
func GetUniqueValidatorIDInstance() *UniqueValidatorID { func GetUniqueValidatorIDInstance() *UniqueValidatorID {
once.Do(func() { onceForUniqueValidatorID.Do(func() {
instance = &UniqueValidatorID{ validatorIDInstance = &UniqueValidatorID{
uniqueID: 0, uniqueID: 0,
} }
}) })
return instance return validatorIDInstance
} }
// GetUniqueID returns a unique ID and increment the internal variable // GetUniqueID returns a unique ID and increment the internal variable

Loading…
Cancel
Save