2019-11-27 19:12:07 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// waitgroup for global management of connections.
|
2019-11-27 19:12:07 +02:00
|
|
|
type waitGroup struct {
|
|
|
|
// global waitgroup
|
|
|
|
gg *sync.WaitGroup
|
2023-04-26 02:16:34 +02:00
|
|
|
// local waitgroup
|
|
|
|
lg sync.WaitGroup
|
2019-11-27 19:12:07 +02:00
|
|
|
}
|
|
|
|
|
2022-10-20 13:00:50 +02:00
|
|
|
// NewWaitGroup returns a new double waitgroup for global management of processes.
|
|
|
|
func NewWaitGroup(gWg *sync.WaitGroup) *waitGroup {
|
|
|
|
return &waitGroup{
|
|
|
|
gg: gWg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:12:07 +02:00
|
|
|
func (w *waitGroup) Add(i int) {
|
|
|
|
w.lg.Add(i)
|
|
|
|
if w.gg != nil {
|
|
|
|
w.gg.Add(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *waitGroup) Done() {
|
|
|
|
w.lg.Done()
|
|
|
|
if w.gg != nil {
|
|
|
|
w.gg.Done()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *waitGroup) Wait() {
|
|
|
|
// only wait on local group
|
|
|
|
w.lg.Wait()
|
|
|
|
}
|