Go written wrapper for sync.WaitGroup to ease the usage of Goroutines.
The main purpose of SyncWaitGroup is to execute and manage the synchronous functions provided as async goroutines; additionally it allows to dynamically add more functions - even by the function currently managed. For convenience SyncWaitGroup provides a default mutex.
func myFunc() {
// do something synchronously...
}
var syncWaitGroup = SyncWaitGroup{}
syncWaitGroup.AddFunction(myFunc)
syncWaitGroup.Wait()
func myFunc() {
// do something synchronously...
}
type myRunnable struct {}
func (runner *myRunnable) Run(syncWaitGroup *SyncWaitGroup) {
// do something synchronously, maybe synchronized via the Mutex provided...
syncWaitGroup.Mutex.Lock()
...
syncWaitGroup.Mutex.Unlock()
// dynamically add more sync code to be executed as Goroutine within this managed Runnable
syncWaitGroup.AddFunction(myFunc)
}
var syncWaitGroup = SyncWaitGroup{}
syncWaitGroup.AddRunnable(myRunnable{})
syncWaitGroup.Wait()