github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/server/util.go (about)

     1  package server
     2  
     3  import (
     4  	"sync"
     5  )
     6  
     7  // waitgroup for global management of connections
     8  type waitGroup struct {
     9  	// local waitgroup
    10  	lg sync.WaitGroup
    11  	// global waitgroup
    12  	gg *sync.WaitGroup
    13  }
    14  
    15  func (w *waitGroup) Add(i int) {
    16  	w.lg.Add(i)
    17  	if w.gg != nil {
    18  		w.gg.Add(i)
    19  	}
    20  }
    21  
    22  func (w *waitGroup) Done() {
    23  	w.lg.Done()
    24  	if w.gg != nil {
    25  		w.gg.Done()
    26  	}
    27  }
    28  
    29  func (w *waitGroup) Wait() {
    30  	// only wait on local group
    31  	w.lg.Wait()
    32  }