My scenario is I want to fire multiple go routines that listens to network traffic, if there is an error in one of the go routine function, function will execute wg.done() and this for loop should wait for other go routines to execute wg.done() and after some time, like ten minutes of sleep this for loop should run again. This is something like a retry logic. Can someone help with this. Thanks. Below is the code I came up with so far.
package main
import (
"errors"
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
for {
wg.Add(1)
go A(&wg)
wg.Add(1)
go B(&wg)
}
wg.Wait()
}
func A(wg *sync.WaitGroup) {
fmt.Println("inside function A")
err := errors.New("There is an error")
if err != nil {
wg.Done()
}
}
func B(wg *sync.WaitGroup) {
fmt.Println("Inside function B")
err := errors.New("There is an error")
if err != nil {
wg.Done()
}
}