Skip to content

Commit

Permalink
Common mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
emilniklas committed Dec 17, 2020
1 parent eebd614 commit 9a45145
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions netlify/resource_branch_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,11 @@ func resourceBranchDeploy() *schema.Resource {
}
}

var mutexes map[string]*sync.Mutex

func getMutex(siteId string) (mutex *sync.Mutex) {
var ok bool
if mutex, ok = mutexes[siteId]; !ok {
mutex = &sync.Mutex{}
mutexes[siteId] = mutex
}
return
}
var mutex sync.Mutex

func resourceBranchDeployCreate(d *schema.ResourceData, metaRaw interface{}) error {
siteId := d.Get("site_id").(string)

mutex := getMutex(siteId)
mutex.Lock()
defer mutex.Unlock()

Expand Down Expand Up @@ -83,7 +73,6 @@ func resourceBranchDeployCreate(d *schema.ResourceData, metaRaw interface{}) err
func resourceBranchDeployRead(d *schema.ResourceData, metaRaw interface{}) error {
siteId := d.Get("site_id").(string)

mutex := getMutex(siteId)
mutex.Lock()
defer mutex.Unlock()

Expand Down Expand Up @@ -111,7 +100,6 @@ func resourceBranchDeployRead(d *schema.ResourceData, metaRaw interface{}) error
func resourceBranchDeployUpdate(d *schema.ResourceData, metaRaw interface{}) error {
siteId := d.Get("site_id").(string)

mutex := getMutex(siteId)
mutex.Lock()
defer mutex.Unlock()

Expand Down Expand Up @@ -151,7 +139,6 @@ func resourceBranchDeployUpdate(d *schema.ResourceData, metaRaw interface{}) err
func resourceBranchDeployDelete(d *schema.ResourceData, metaRaw interface{}) error {
siteId := d.Get("site_id").(string)

mutex := getMutex(siteId)
mutex.Lock()
defer mutex.Unlock()

Expand Down

0 comments on commit 9a45145

Please sign in to comment.