GODT-1367: Use sync.Once to only close pool jobs once

This commit is contained in:
James Houlahan
2021-10-04 08:22:40 +02:00
committed by Jakub
parent 10da4f284c
commit 8ea610c625
2 changed files with 9 additions and 15 deletions

View File

@ -26,6 +26,7 @@ type PChan struct {
lock sync.Mutex
items []*Item
ready, done chan struct{}
once sync.Once
}
type Item struct {
@ -82,13 +83,7 @@ func (ch *PChan) Pop() (interface{}, int, bool) {
}
func (ch *PChan) Close() {
select {
case <-ch.done:
return
default:
close(ch.done)
}
ch.once.Do(func() { close(ch.done) })
}
func (ch *PChan) push(val interface{}, prio int) *Item {