Skip to content

Commit 9268cff

Browse files
committed
fix build async
1 parent 65a863c commit 9268cff

File tree

1 file changed

+4
-7
lines changed
  • src/commonMain/kotlin/com.adamratzman.spotify

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import com.adamratzman.spotify.http.HttpRequestMethod
66
import com.adamratzman.spotify.models.SpotifyAuthenticationException
77
import com.adamratzman.spotify.models.Token
88
import com.adamratzman.spotify.models.serialization.toObject
9-
import kotlinx.coroutines.Dispatchers
109
import kotlinx.coroutines.GlobalScope
1110
import kotlinx.coroutines.Job
12-
import kotlinx.coroutines.coroutineScope
1311
import kotlinx.coroutines.launch
14-
import kotlinx.coroutines.withContext
1512

1613
// Kotlin DSL builders
1714

@@ -214,7 +211,7 @@ interface ISpotifyClientApiBuilder : ISpotifyApiBuilder {
214211
*
215212
* Provide a consumer object to be executed after the client has been successfully built
216213
*/
217-
suspend fun buildAsync(consumer: (SpotifyClientApi) -> Unit)
214+
suspend fun buildAsync(consumer: (SpotifyClientApi) -> Unit): Job
218215

219216
/**
220217
* Create a Spotify authorization URL from which API access can be obtained
@@ -313,8 +310,8 @@ class SpotifyClientApiBuilder(
313310
}
314311
}
315312

316-
override suspend fun buildAsync(consumer: (SpotifyClientApi) -> Unit) = coroutineScope {
317-
withContext(Dispatchers.Default) { consumer(build()) }
313+
override suspend fun buildAsync(consumer: (SpotifyClientApi) -> Unit) = GlobalScope.launch {
314+
consumer(build())
318315
}
319316
}
320317

@@ -348,7 +345,7 @@ class SpotifyAppApiBuilder(
348345
* Provide a consumer object to be executed after the api has been successfully built
349346
*/
350347
override fun buildAsync(consumer: (SpotifyApi) -> Unit) = GlobalScope.launch {
351-
withContext(Dispatchers.Default) { consumer(build()) }
348+
consumer(build())
352349
}
353350

354351
/**

0 commit comments

Comments
 (0)