mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
40 lines
603 B
Go
40 lines
603 B
Go
package server
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// waitgroup for global management of connections.
|
|
type waitGroup struct {
|
|
// global waitgroup
|
|
gg *sync.WaitGroup
|
|
// local waitgroup
|
|
lg sync.WaitGroup
|
|
}
|
|
|
|
// NewWaitGroup returns a new double waitgroup for global management of processes.
|
|
func NewWaitGroup(gWg *sync.WaitGroup) *waitGroup {
|
|
return &waitGroup{
|
|
gg: gWg,
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|