Skip to content

Commit 21640b6

Browse files
committed
change rest action complete()s to suspendComplete
1 parent 5f7442f commit 21640b6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyRestAction.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,21 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
137137
/**
138138
* Synchronously retrieve all [AbstractPagingObject] associated with this rest action
139139
*/
140-
fun getAll() = api.tracks.toAction { complete().getAllImpl() }
140+
fun getAll(context: CoroutineContext = Dispatchers.Default) = api.tracks.toAction { suspendComplete(context).getAllImpl() }
141141

142142
/**
143143
* Synchronously retrieve all [Z] associated with this rest action
144144
*/
145-
fun getAllItems() = api.tracks.toAction { complete().getAllImpl().toList().map { it.items }.flatten() }
145+
fun getAllItems(context: CoroutineContext = Dispatchers.Default) =
146+
api.tracks.toAction { suspendComplete(context)
147+
.getAllImpl().toList().map { it.items }.flatten() }
146148

147149
/**
148150
* Consume each [Z] by [consumer] as it is retrieved
149151
*/
150-
fun streamAllItems(consumer: (Z) -> Unit): SpotifyRestAction<Unit> {
152+
fun streamAllItems(context: CoroutineContext = Dispatchers.Default, consumer: (Z) -> Unit): SpotifyRestAction<Unit> {
151153
return api.tracks.toAction {
152-
complete().getAllImpl().toList().forEach { it.items.forEach { item -> consumer(item) } }
154+
suspendComplete(context).getAllImpl().toList().forEach { it.items.forEach { item -> consumer(item) } }
153155
}
154156
}
155157

@@ -170,7 +172,7 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
170172
@ExperimentalCoroutinesApi
171173
fun flowPagingObjectsOrdered(context: CoroutineContext = Dispatchers.Default): Flow<AbstractPagingObject<Z>> =
172174
flow {
173-
complete().also { master ->
175+
suspendComplete(context).also { master ->
174176
emitAll(master.flowStartOrdered())
175177
emit(master)
176178
emitAll(master.flowEndOrdered())

0 commit comments

Comments
 (0)