Skip to content

Commit

Permalink
minor best practice style improvement - stops extra allocations on on…
Browse files Browse the repository at this point in the history
…ce-calls
  • Loading branch information
josephcopenhaver committed Oct 18, 2024
1 parent 1a97974 commit a28e4c6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions loadtester/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,14 @@ func main() {
//

// define input handling channel and closer
inputChan := make(chan string)
closeInputChan := func() func() {
var once sync.Once
inputChan, closeInputChan := func() (chan string, func()) {
c := make(chan string)

c := inputChan
closer := sync.OnceFunc(func() {
close(c)
})

return func() {
once.Do(func() {
close(c)
})
}
return c, closer
}()

//
Expand Down Expand Up @@ -169,7 +166,7 @@ func main() {

// note it's possible for this channel
// write to panic due to the user
// doing thing really fast and pressing control-c afterward
// doing things really fast and pressing control-c afterward
//
// but in that case we're still going through the stop procedure so meh

Expand Down

0 comments on commit a28e4c6

Please sign in to comment.