Skip to content
Snippets Groups Projects
Commit 4ce8d5a8 authored by Josh Brooks's avatar Josh Brooks
Browse files

Refactor verify-send logic to use for loop instead of goto

parent a8be1ca0
No related branches found
No related tags found
2 merge requests!117Release,!76Xx 3578/send with verification
...@@ -198,7 +198,8 @@ var rootCmd = &cobra.Command{ ...@@ -198,7 +198,8 @@ var rootCmd = &cobra.Command{
go func(i int) { go func(i int) {
defer wg.Done() defer wg.Done()
fmt.Printf("Sending to %s: %s\n", recipientID, msgBody) fmt.Printf("Sending to %s: %s\n", recipientID, msgBody)
sendLoop: for {
// Send messages
var roundIDs []id.Round var roundIDs []id.Round
var roundTimeout time.Duration var roundTimeout time.Duration
if unsafe { if unsafe {
...@@ -214,9 +215,10 @@ var rootCmd = &cobra.Command{ ...@@ -214,9 +215,10 @@ var rootCmd = &cobra.Command{
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
if viper.GetBool("verify-sends") { // Verify message sends were successful
retryChan := make(chan struct{}) retryChan := make(chan struct{})
done := make(chan struct{}, 1) done := make(chan struct{}, 1)
if viper.GetBool("verify-sends") { // Verify message sends were successful
// Construct the callback function which // Construct the callback function which
// verifies successful message send or retries // verifies successful message send or retries
f := func(allRoundsSucceeded, timedOut bool, f := func(allRoundsSucceeded, timedOut bool,
...@@ -232,15 +234,18 @@ var rootCmd = &cobra.Command{ ...@@ -232,15 +234,18 @@ var rootCmd = &cobra.Command{
err = client.GetRoundResults(roundIDs, roundTimeout, f) err = client.GetRoundResults(roundIDs, roundTimeout, f)
if err != nil { if err != nil {
jww.DEBUG.Printf("Could not verify messages were sent successfully, resending messages...") jww.DEBUG.Printf("Could not verify messages were sent successfully, resending messages...")
goto sendLoop continue
} }
select { select {
case <-retryChan: case <-retryChan:
// On a retry, go to the top of the loop // On a retry, go to the top of the loop
jww.DEBUG.Printf("Could not verify messages were sent successfully, resending messages...") jww.DEBUG.Printf("Messages were not sent successfully, resending messages...")
goto sendLoop continue
case <-done: case <-done:
// Close channels on verification success
close(retryChan)
close(done)
break break
} }
...@@ -260,11 +265,11 @@ var rootCmd = &cobra.Command{ ...@@ -260,11 +265,11 @@ var rootCmd = &cobra.Command{
if err != nil { if err != nil {
jww.FATAL.Panicf("Message sending for send %d failed: %+v", i, err) jww.FATAL.Panicf("Message sending for send %d failed: %+v", i, err)
} }
}
close(done) }
close(retryChan)
break
}
}(i) }(i)
} }
}() }()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment