Skip to content

Commit

Permalink
replace sync.OnceFunc with sync.Once.Do
Browse files Browse the repository at this point in the history
  • Loading branch information
dncohen committed Jul 19, 2024
1 parent fcb3261 commit dfca6cb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func alert(exception error) error {
defer timer.Stop()

done := make(chan struct{})
finish := sync.OnceFunc(func() {close(done)})
finish := func() {close(done)}
var once sync.Once
var mu sync.Mutex

// start a goroutine for each handler
Expand All @@ -185,7 +186,7 @@ func alert(exception error) error {
default:
e.id[provider] = id
if len(e.id) == len(capture) {
finish()
once.Do(finish)
}
}
}()
Expand All @@ -197,8 +198,8 @@ waitLoop:
select {
case <- timer.C:
mu.Lock()
defer mu.Unlock()
finish()
once.Do(finish)
mu.Unlock()
case <- done:
break waitLoop
}
Expand Down

0 comments on commit dfca6cb

Please sign in to comment.