File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
src/commonMain/kotlin/com.adamratzman.spotify/http Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,22 @@ import com.adamratzman.spotify.utils.ConcurrentHashMap
17
17
import com.adamratzman.spotify.utils.getCurrentTimeMs
18
18
import kotlin.math.ceil
19
19
import kotlinx.coroutines.TimeoutCancellationException
20
+ import kotlinx.coroutines.coroutineScope
21
+ import kotlinx.coroutines.launch
20
22
import kotlinx.coroutines.withTimeout
21
23
22
24
abstract class SpotifyEndpoint (val api : SpotifyApi <* , * >) {
23
25
val cache = SpotifyCache ()
24
26
internal val json get() = api.json
25
27
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
+
26
36
internal suspend fun get (url : String ): String {
27
37
return execute(url)
28
38
}
You can’t perform that action at this time.
0 commit comments