Skip to content

Commit 52338dc

Browse files
committed
allow chunked requests
1 parent 0e5fdae commit 52338dc

File tree

1 file changed

+10
-0
lines changed
  • src/commonMain/kotlin/com.adamratzman.spotify/http

1 file changed

+10
-0
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/http/Endpoints.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@ import com.adamratzman.spotify.utils.ConcurrentHashMap
1717
import com.adamratzman.spotify.utils.getCurrentTimeMs
1818
import kotlin.math.ceil
1919
import kotlinx.coroutines.TimeoutCancellationException
20+
import kotlinx.coroutines.coroutineScope
21+
import kotlinx.coroutines.launch
2022
import kotlinx.coroutines.withTimeout
2123

2224
abstract class SpotifyEndpoint(val api: SpotifyApi<*, *>) {
2325
val cache = SpotifyCache()
2426
internal val json get() = api.json
2527

28+
internal suspend fun <T> chunk(limit: Int, objects: List<T>, consumer: suspend (List<T>) -> Unit) {
29+
coroutineScope {
30+
objects.chunked(limit).forEach { chunk ->
31+
launch { consumer(chunk) }
32+
}
33+
}
34+
}
35+
2636
internal suspend fun get(url: String): String {
2737
return execute(url)
2838
}

0 commit comments

Comments
 (0)