mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-05 12:58:33 +02:00
Simplify context cancellation checks
This commit is contained in:
parent
4a66e3d432
commit
20853f7601
5 changed files with 53 additions and 68 deletions
|
@ -103,13 +103,11 @@ func (b *LastfmApiBackend) ExportListens(ctx context.Context, oldestTimestamp ti
|
|||
|
||||
out:
|
||||
for page > 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
results <- models.ListensResult{Error: ctx.Err()}
|
||||
if err := ctx.Err(); err != nil {
|
||||
results <- models.ListensResult{Error: err}
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
args := lastfm.P{
|
||||
|
@ -195,10 +193,8 @@ out:
|
|||
func (b *LastfmApiBackend) ImportListens(ctx context.Context, export models.ListensResult, importResult models.ImportResult, progress chan models.TransferProgress) (models.ImportResult, error) {
|
||||
total := len(export.Items)
|
||||
for i := 0; i < total; i += MaxListensPerSubmission {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return importResult, ctx.Err()
|
||||
default:
|
||||
if err := ctx.Err(); err != nil {
|
||||
return importResult, err
|
||||
}
|
||||
|
||||
listens := export.Items[i:min(i+MaxListensPerSubmission, total)]
|
||||
|
@ -290,13 +286,11 @@ func (b *LastfmApiBackend) ExportLoves(ctx context.Context, oldestTimestamp time
|
|||
|
||||
out:
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
results <- models.LovesResult{Error: ctx.Err()}
|
||||
if err := ctx.Err(); err != nil {
|
||||
results <- models.LovesResult{Error: err}
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
result, err := b.client.User.GetLovedTracks(lastfm.P{
|
||||
|
@ -362,10 +356,8 @@ out:
|
|||
|
||||
func (b *LastfmApiBackend) ImportLoves(ctx context.Context, export models.LovesResult, importResult models.ImportResult, progress chan models.TransferProgress) (models.ImportResult, error) {
|
||||
for _, love := range export.Items {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return importResult, ctx.Err()
|
||||
default:
|
||||
if err := ctx.Err(); err != nil {
|
||||
return importResult, err
|
||||
}
|
||||
|
||||
err := b.client.Track.Love(lastfm.P{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue