mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-12 11:07:04 +02:00
Use a WaitGroup to wait for both export and import goroutine to finish
This commit is contained in:
parent
17cee9cb8b
commit
a87c42059f
4 changed files with 26 additions and 14 deletions
|
@ -60,8 +60,7 @@ func setupProgressBars(updateChan chan models.TransferProgress) progressBarUpdat
|
|||
return u
|
||||
}
|
||||
|
||||
func (u *progressBarUpdater) wait() {
|
||||
// FIXME: This should probably be closed elsewhere
|
||||
func (u *progressBarUpdater) close() {
|
||||
close(u.updateChan)
|
||||
u.progress.Wait()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue