From 9beee9f6022a745a40537c0b5d26dc8a43d35944 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 27 Sep 2019 11:07:16 +0200 Subject: Create a factory method for Domains to handle mutex better --- internal/source/domains.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'internal/source/domains.go') diff --git a/internal/source/domains.go b/internal/source/domains.go index 54a269d8..85646b8a 100644 --- a/internal/source/domains.go +++ b/internal/source/domains.go @@ -13,7 +13,16 @@ import ( // currently reading them from disk. type Domains struct { dm disk.Map - lock sync.RWMutex + lock *sync.RWMutex +} + +// NewDomains is a factory method for domains initializing a mutex. It should +// not initialize `dm` as we later check the readiness by comparing it with a +// nil value. +func NewDomains() *Domains { + return &Domains{ + lock: new(sync.RWMutex), + } } // GetDomain returns a domain from the domains map -- cgit v1.2.3