I have a function calling a go routine that calls additional functions within it. However, those go routines are exiting before being completely finished. How would I make sure all the underlying code within the function (migrateUserHelper) runs before the exit. Here is my code below:
func MigrateUsers(){
var wg sync.WaitGroup
userCount:=10 //userDAO.GetUserCount()
limitSize:=2
count:=0
divisor = userCount/limitSize
for divisor>0{
wg.Add(1)
go migrateUserHelper(limitSize,&wg,count)
divisor =divisor -1
count=count +1
}
wg.Wait()
fm.Println("DONE BATCHES")
}
func migrateUserHelper(limitSize int, count int, wg *sync.WaitGroup)
{
defer wg.Done()
fmt.Println("Start batch "+strconv.Itoa(count))
users:= userDAO.GetUsers(limitSize)
fmt.Println("Fetched Users for batch "+ strconv.Itoa(count))
userDAO.BulkUpdateUsers(users)
fmt.Println("Reconciled Users for batch "+ strconv.Itoa(count))
}
Im trying to update A LOT OF records in the database simultaneously in different go routines.
Thanks