mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-05 04:58:33 +02:00
Prepare using a context for export / import
This will allow cancelling the export if the import fails before the export finished. For now the context isn't passed on to the actual export functions, hence there is not yet any cancellation happening.
This commit is contained in:
parent
536fae6a46
commit
3b545a0fd6
3 changed files with 37 additions and 16 deletions
|
@ -16,6 +16,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package backends
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -24,7 +25,7 @@ import (
|
|||
|
||||
type ExportProcessor[T models.ListensResult | models.LovesResult] interface {
|
||||
ExportBackend() models.Backend
|
||||
Process(wg *sync.WaitGroup, oldestTimestamp time.Time, results chan T, progress chan models.TransferProgress)
|
||||
Process(ctx context.Context, wg *sync.WaitGroup, oldestTimestamp time.Time, results chan T, progress chan models.TransferProgress)
|
||||
}
|
||||
|
||||
type ListensExportProcessor struct {
|
||||
|
@ -35,7 +36,7 @@ func (p ListensExportProcessor) ExportBackend() models.Backend {
|
|||
return p.Backend
|
||||
}
|
||||
|
||||
func (p ListensExportProcessor) Process(wg *sync.WaitGroup, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
func (p ListensExportProcessor) Process(ctx context.Context, wg *sync.WaitGroup, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
defer close(results)
|
||||
|
@ -50,7 +51,7 @@ func (p LovesExportProcessor) ExportBackend() models.Backend {
|
|||
return p.Backend
|
||||
}
|
||||
|
||||
func (p LovesExportProcessor) Process(wg *sync.WaitGroup, oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.TransferProgress) {
|
||||
func (p LovesExportProcessor) Process(ctx context.Context, wg *sync.WaitGroup, oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.TransferProgress) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
defer close(results)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue