mirror of
https://git.sr.ht/~phw/scotty
synced 2025-07-01 07:41:57 +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
|
@ -18,12 +18,14 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package backends
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"go.uploadedlobster.com/scotty/internal/models"
|
||||
)
|
||||
|
||||
type ImportProcessor[T models.ListensResult | models.LovesResult] interface {
|
||||
ImportBackend() models.ImportBackend
|
||||
Process(results chan T, out chan models.ImportResult, progress chan models.TransferProgress)
|
||||
Process(wg *sync.WaitGroup, results chan T, out chan models.ImportResult, progress chan models.TransferProgress)
|
||||
Import(export T, result models.ImportResult, out chan models.ImportResult, progress chan models.TransferProgress) (models.ImportResult, error)
|
||||
}
|
||||
|
||||
|
@ -35,8 +37,8 @@ func (p ListensImportProcessor) ImportBackend() models.ImportBackend {
|
|||
return p.Backend
|
||||
}
|
||||
|
||||
func (p ListensImportProcessor) Process(results chan models.ListensResult, out chan models.ImportResult, progress chan models.TransferProgress) {
|
||||
process(p, results, out, progress)
|
||||
func (p ListensImportProcessor) Process(wg *sync.WaitGroup, results chan models.ListensResult, out chan models.ImportResult, progress chan models.TransferProgress) {
|
||||
process(wg, p, results, out, progress)
|
||||
}
|
||||
|
||||
func (p ListensImportProcessor) Import(export models.ListensResult, result models.ImportResult, out chan models.ImportResult, progress chan models.TransferProgress) (models.ImportResult, error) {
|
||||
|
@ -64,8 +66,8 @@ func (p LovesImportProcessor) ImportBackend() models.ImportBackend {
|
|||
return p.Backend
|
||||
}
|
||||
|
||||
func (p LovesImportProcessor) Process(results chan models.LovesResult, out chan models.ImportResult, progress chan models.TransferProgress) {
|
||||
process(p, results, out, progress)
|
||||
func (p LovesImportProcessor) Process(wg *sync.WaitGroup, results chan models.LovesResult, out chan models.ImportResult, progress chan models.TransferProgress) {
|
||||
process(wg, p, results, out, progress)
|
||||
}
|
||||
|
||||
func (p LovesImportProcessor) Import(export models.LovesResult, result models.ImportResult, out chan models.ImportResult, progress chan models.TransferProgress) (models.ImportResult, error) {
|
||||
|
@ -85,7 +87,9 @@ func (p LovesImportProcessor) Import(export models.LovesResult, result models.Im
|
|||
return importResult, nil
|
||||
}
|
||||
|
||||
func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](processor P, results chan R, out chan models.ImportResult, progress chan models.TransferProgress) {
|
||||
func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](wg *sync.WaitGroup, processor P, results chan R, out chan models.ImportResult, progress chan models.TransferProgress) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
defer close(out)
|
||||
result := models.ImportResult{}
|
||||
p := models.TransferProgress{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue