From 16245e495dbb0d696a91385bb4dc5d5ab1fb0010 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Fri, 2 May 2025 08:36:59 +0200 Subject: [PATCH] Handle wait group for progress bar centrally This does not need to be exposed and caller only needs to wait for the Progress instance. --- internal/cli/progress.go | 5 +++-- internal/cli/transfer.go | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/cli/progress.go b/internal/cli/progress.go index 6d4421d..54ee4a8 100644 --- a/internal/cli/progress.go +++ b/internal/cli/progress.go @@ -1,5 +1,5 @@ /* -Copyright © 2023 Philipp Wolfer +Copyright © 2023-2025 Philipp Wolfer This file is part of Scotty. @@ -28,7 +28,8 @@ import ( "go.uploadedlobster.com/scotty/internal/models" ) -func progressBar(wg *sync.WaitGroup, exportProgress chan models.Progress, importProgress chan models.Progress) *mpb.Progress { +func progressBar(exportProgress chan models.Progress, importProgress chan models.Progress) *mpb.Progress { + wg := &sync.WaitGroup{} p := mpb.New( mpb.WithWaitGroup(wg), mpb.WithOutput(color.Output), diff --git a/internal/cli/transfer.go b/internal/cli/transfer.go index 0ba04b9..4777042 100644 --- a/internal/cli/transfer.go +++ b/internal/cli/transfer.go @@ -1,5 +1,5 @@ /* -Copyright © 2023 Philipp Wolfer +Copyright © 2023-2025 Philipp Wolfer Scotty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -19,7 +19,6 @@ import ( "errors" "fmt" "strconv" - "sync" "time" "github.com/spf13/cobra" @@ -112,8 +111,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac // Prepare progress bars exportProgress := make(chan models.Progress) importProgress := make(chan models.Progress) - var wg sync.WaitGroup - progress := progressBar(&wg, exportProgress, importProgress) + progress := progressBar(exportProgress, importProgress) // Export from source exportChan := make(chan R, 1000) @@ -126,7 +124,6 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac if timestamp.After(result.LastTimestamp) { result.LastTimestamp = timestamp } - wg.Wait() progress.Wait() if result.Error != nil { printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)