Use a WaitGroup to wait for both export and import goroutine to finish

This commit is contained in:
Philipp Wolfer 2025-05-05 17:49:44 +02:00
parent 17cee9cb8b
commit a87c42059f
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
4 changed files with 26 additions and 14 deletions

View file

@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"strconv"
"sync"
"time"
"github.com/spf13/cobra"
@ -112,15 +113,18 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
progressChan := make(chan models.TransferProgress)
progress := setupProgressBars(progressChan)
wg := &sync.WaitGroup{}
// Export from source
exportChan := make(chan R, 1000)
go exp.Process(timestamp, exportChan, progressChan)
go exp.Process(wg, timestamp, exportChan, progressChan)
// Import into target
resultChan := make(chan models.ImportResult)
go imp.Process(exportChan, resultChan, progressChan)
go imp.Process(wg, exportChan, resultChan, progressChan)
result := <-resultChan
progress.wait()
wg.Wait()
progress.close()
// Update timestamp
err = c.updateTimestamp(&result, timestamp)