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
}
var instance *UniqueValidatorID
var validatorIDInstance *UniqueValidatorID
var logInstance log.Logger
var once sync.Once
var onceForUniqueValidatorID sync.Once
var onceForLog sync.Once
// GetUniqueValidatorIDInstance returns a singleton instance
func GetUniqueValidatorIDInstance() *UniqueValidatorID {
once.Do(func() {
instance = &UniqueValidatorID{
onceForUniqueValidatorID.Do(func() {
validatorIDInstance = &UniqueValidatorID{
uniqueID: 0,
}
})
return instance
return validatorIDInstance
}
// GetUniqueID returns a unique ID and increment the internal variable

Loading…
Cancel
Save