Skip to content

Commit 8ca49aa

Browse files
committed
feat: limit time for fetching context tracks
1 parent 1642ca1 commit 8ca49aa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tracks/tracks.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"slices"
7+
"time"
78

89
librespot "github.com/devgianlu/go-librespot"
910
connectpb "github.com/devgianlu/go-librespot/proto/spotify/connectstate"
@@ -147,6 +148,11 @@ func (tl *List) NextTracks(ctx context.Context, nextHint []*connectpb.ContextTra
147148
tracks = append(tracks, librespot.ContextTrackToProvidedTrack(tl.ctx.Type(), curr))
148149
}
149150
} else {
151+
// Do not waste too much time fetching next tracks. Even if we do not fetch everything in time,
152+
// the playback will continue anyway.
153+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
154+
defer cancel()
155+
150156
iter := tl.tracks.iterHere()
151157
for len(tracks) < MaxTracksInContext && iter.next(ctx) {
152158
curr := iter.get()

0 commit comments

Comments
 (0)