Added wait group
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
appConfig "github.com/xmpploadtesting/config"
|
appConfig "github.com/xmpploadtesting/config"
|
||||||
@@ -91,8 +92,10 @@ func Init() {
|
|||||||
log.Printf("Client credentials length %v", len(clientCredentials))
|
log.Printf("Client credentials length %v", len(clientCredentials))
|
||||||
|
|
||||||
xmppService.XMPPClients = make([]XMPPClient, 0)
|
xmppService.XMPPClients = make([]XMPPClient, 0)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for _, credential := range clientCredentials {
|
for _, credential := range clientCredentials {
|
||||||
|
wg.Add(1)
|
||||||
log.Printf("Host %v", credential.Host+":"+strconv.Itoa(credential.Port))
|
log.Printf("Host %v", credential.Host+":"+strconv.Itoa(credential.Port))
|
||||||
log.Printf("Jid %v", credential.Jid+"@"+credential.Host)
|
log.Printf("Jid %v", credential.Jid+"@"+credential.Host)
|
||||||
log.Printf("Port %v", credential.Port)
|
log.Printf("Port %v", credential.Port)
|
||||||
@@ -114,6 +117,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
client, err := xmpp.NewClient(&xmppClient.Config, xmppService.Router, errorHandler)
|
client, err := xmpp.NewClient(&xmppClient.Config, xmppService.Router, errorHandler)
|
||||||
|
|
||||||
@@ -133,8 +137,10 @@ func Init() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
// Delay For two seccond to allow all clients to connect
|
// // Delay For two seccond to allow all clients to connect
|
||||||
time.Sleep(time.Duration(2000000000))
|
// time.Sleep(time.Duration(2000000000))
|
||||||
|
// Wait untill all client connections are open sucessfuly
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user