@@ -24,13 +24,13 @@ import dagger.hilt.android.qualifiers.ApplicationContext
24
24
import kotlinx.coroutines.CoroutineScope
25
25
import kotlinx.coroutines.Dispatchers
26
26
import kotlinx.coroutines.launch
27
+ import kotlinx.coroutines.suspendCancellableCoroutine
27
28
import kotlinx.coroutines.withContext
28
29
import org.edx.mobile.extenstion.encodeToString
30
+ import org.edx.mobile.extenstion.resumeIfActive
29
31
import org.edx.mobile.logger.Logger
30
32
import javax.inject.Inject
31
33
import javax.inject.Singleton
32
- import kotlin.coroutines.resume
33
- import kotlin.coroutines.suspendCoroutine
34
34
35
35
/* *
36
36
* The BillingProcessor implements all billing functionality for application.
@@ -69,14 +69,14 @@ class BillingProcessor @Inject constructor(
69
69
}
70
70
71
71
private suspend fun connect (): Boolean {
72
- return suspendCoroutine { continuation ->
72
+ return suspendCancellableCoroutine { continuation ->
73
73
billingClientStateListener = object : BillingClientStateListener {
74
74
override fun onBillingSetupFinished (billingResult : BillingResult ) {
75
75
logger.debug(" BillingSetupFinished -> $billingResult " )
76
76
if (billingResult.responseCode == BillingResponseCode .OK ) {
77
- continuation.resume (true )
77
+ continuation.resumeIfActive (true )
78
78
} else {
79
- continuation.resume (false )
79
+ continuation.resumeIfActive (false )
80
80
}
81
81
}
82
82
@@ -89,7 +89,7 @@ class BillingProcessor @Inject constructor(
89
89
connectionTryCount++
90
90
retryBillingServiceConnectionWithExponentialBackoff()
91
91
}
92
- continuation.resume (false )
92
+ continuation.resumeIfActive (false )
93
93
}
94
94
}
95
95
billingClient.startConnection(billingClientStateListener)
0 commit comments