GODT-1367: use waitgroup instead of channel in pool/pchan

This commit is contained in:
James Houlahan
2021-10-05 15:03:24 +02:00
committed by Jakub
parent 8ea610c625
commit bc21bb1d8d
2 changed files with 17 additions and 17 deletions

View File

@ -33,11 +33,11 @@ type Item struct {
ch *PChan
val interface{}
prio int
done chan struct{}
done sync.WaitGroup
}
func (item *Item) Wait() {
<-item.done
item.done.Wait()
}
func (item *Item) GetPriority() int {
@ -90,15 +90,14 @@ func (ch *PChan) push(val interface{}, prio int) *Item {
ch.lock.Lock()
defer ch.lock.Unlock()
done := make(chan struct{})
item := &Item{
ch: ch,
val: val,
prio: prio,
done: done,
}
item.done.Add(1)
ch.items = append(ch.items, item)
return item
@ -116,7 +115,7 @@ func (ch *PChan) pop() (interface{}, int) {
item, ch.items = ch.items[len(ch.items)-1], ch.items[:len(ch.items)-1]
defer close(item.done)
defer item.done.Done()
return item.val, item.prio
}