@@ -137,19 +137,21 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
137
137
/* *
138
138
* Synchronously retrieve all [AbstractPagingObject] associated with this rest action
139
139
*/
140
- fun getAll () = api.tracks.toAction { complete( ).getAllImpl() }
140
+ fun getAll (context : CoroutineContext = Dispatchers . Default ) = api.tracks.toAction { suspendComplete(context ).getAllImpl() }
141
141
142
142
/* *
143
143
* Synchronously retrieve all [Z] associated with this rest action
144
144
*/
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() }
146
148
147
149
/* *
148
150
* Consume each [Z] by [consumer] as it is retrieved
149
151
*/
150
- fun streamAllItems (consumer : (Z ) -> Unit ): SpotifyRestAction <Unit > {
152
+ fun streamAllItems (context : CoroutineContext = Dispatchers . Default , consumer : (Z ) -> Unit ): SpotifyRestAction <Unit > {
151
153
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) } }
153
155
}
154
156
}
155
157
@@ -170,7 +172,7 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
170
172
@ExperimentalCoroutinesApi
171
173
fun flowPagingObjectsOrdered (context : CoroutineContext = Dispatchers .Default ): Flow <AbstractPagingObject <Z >> =
172
174
flow {
173
- complete( ).also { master ->
175
+ suspendComplete(context ).also { master ->
174
176
emitAll(master.flowStartOrdered())
175
177
emit(master)
176
178
emitAll(master.flowEndOrdered())
0 commit comments