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
|
@ -16,6 +16,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package backends
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uploadedlobster.com/scotty/internal/models"
|
||||
|
@ -23,7 +24,7 @@ import (
|
|||
|
||||
type ExportProcessor[T models.ListensResult | models.LovesResult] interface {
|
||||
ExportBackend() models.Backend
|
||||
Process(oldestTimestamp time.Time, results chan T, progress chan models.TransferProgress)
|
||||
Process(wg *sync.WaitGroup, oldestTimestamp time.Time, results chan T, progress chan models.TransferProgress)
|
||||
}
|
||||
|
||||
type ListensExportProcessor struct {
|
||||
|
@ -34,7 +35,9 @@ func (p ListensExportProcessor) ExportBackend() models.Backend {
|
|||
return p.Backend
|
||||
}
|
||||
|
||||
func (p ListensExportProcessor) Process(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
func (p ListensExportProcessor) Process(wg *sync.WaitGroup, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
defer close(results)
|
||||
p.Backend.ExportListens(oldestTimestamp, results, progress)
|
||||
}
|
||||
|
@ -47,7 +50,9 @@ func (p LovesExportProcessor) ExportBackend() models.Backend {
|
|||
return p.Backend
|
||||
}
|
||||
|
||||
func (p LovesExportProcessor) Process(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.TransferProgress) {
|
||||
func (p LovesExportProcessor) Process(wg *sync.WaitGroup, oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.TransferProgress) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
defer close(results)
|
||||
p.Backend.ExportLoves(oldestTimestamp, results, progress)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue