Skip to content

Commit

Permalink
fix: #35 continuation.resume when continuation isActive
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4rl3x committed Sep 14, 2021
1 parent c97fcfb commit 31f0f85
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion billing/src/main/java/de/charlex/billing/BillingHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.android.billingclient.api.queryPurchasesAsync
import com.android.billingclient.api.querySkuDetails

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
Expand Down Expand Up @@ -51,11 +52,14 @@ class BillingHelper(private val activity: Activity, billingClientBuilder: Billin
*
* false: The billing client is NOT ready or disconnected.
*/
private suspend fun startConnectionIfNecessary() = suspendCoroutine<Boolean> { continuation ->
private suspend fun startConnectionIfNecessary() = suspendCancellableCoroutine<Boolean> { continuation ->
if (!billingClient.isReady) {
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
Log.d("BillingHelper", "The billing client is disconnected.")
if(continuation.isActive) {
continuation.resume(false)
}
}

override fun onBillingSetupFinished(billingResult: BillingResult) {
Expand Down

0 comments on commit 31f0f85

Please sign in to comment.