@@ -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
@@ -159,7 +161,7 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
159
161
@FlowPreview
160
162
@JvmOverloads
161
163
@ExperimentalCoroutinesApi
162
- fun flowOrdered (context : CoroutineContext = Dispatchers .Default ): Flow <Z > = flow< Z > {
164
+ fun flowOrdered (context : CoroutineContext = Dispatchers .Default ): Flow <Z > = flow {
163
165
emitAll(flowPagingObjectsOrdered().flatMapConcat { it.asFlow() })
164
166
}.flowOn(context)
165
167
@@ -169,8 +171,8 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
169
171
@JvmOverloads
170
172
@ExperimentalCoroutinesApi
171
173
fun flowPagingObjectsOrdered (context : CoroutineContext = Dispatchers .Default ): Flow <AbstractPagingObject <Z >> =
172
- flow< AbstractPagingObject < Z >> {
173
- complete( ).also { master ->
174
+ flow {
175
+ suspendComplete(context ).also { master ->
174
176
emitAll(master.flowStartOrdered())
175
177
emit(master)
176
178
emitAll(master.flowEndOrdered())
@@ -183,7 +185,7 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
183
185
@FlowPreview
184
186
@JvmOverloads
185
187
@ExperimentalCoroutinesApi
186
- fun flow (context : CoroutineContext = Dispatchers .Default ): Flow <Z > = flow< Z > {
188
+ fun flow (context : CoroutineContext = Dispatchers .Default ): Flow <Z > = flow {
187
189
emitAll(flowPagingObjects().flatMapConcat { it.asFlow() })
188
190
}.flowOn(context)
189
191
@@ -193,8 +195,8 @@ class SpotifyRestActionPaging<Z : Any, T : AbstractPagingObject<Z>>(api: Spotify
193
195
@JvmOverloads
194
196
@ExperimentalCoroutinesApi
195
197
fun flowPagingObjects (context : CoroutineContext = Dispatchers .Default ): Flow <AbstractPagingObject <Z >> =
196
- flow< AbstractPagingObject < Z >> {
197
- complete( ).also { master ->
198
+ flow {
199
+ suspendComplete(context ).also { master ->
198
200
emitAll(master.flowBackward())
199
201
emit(master)
200
202
emitAll(master.flowForward())
0 commit comments