Prateek Grover
01/02/2020, 9:11 AMprivate suspend fun syncFromNewtork(url: String): Boolean = suspendCoroutine { continuation ->
val knResponseCallback: KNSyncManagerResponseCallBack = freezeObject(KNSyncManagerResponseCallBack(continuation))
knNetworkBridge.makePostRestRequest(url: url)
}
class KNSyncManagerResponseCallBack(private val continuation: Continuation<Boolean>): KNResponseCallback {
override fun onSuccess(response: Any?) {
continuation.resume(true)
}
override fun onError(errorResponse: Any?) {
continuation.resume(false)
}
}
Prateek Grover
01/02/2020, 9:13 AMKris Wong
01/02/2020, 2:13 PMbasher
01/02/2020, 2:14 PMbasher
01/02/2020, 2:15 PMPrateek Grover
01/02/2020, 2:17 PMbasher
01/02/2020, 2:18 PMPrateek Grover
01/02/2020, 2:19 PMPrateek Grover
01/02/2020, 2:20 PMbasher
01/02/2020, 2:21 PMPrateek Grover
01/02/2020, 2:21 PMbasher
01/02/2020, 2:21 PMbasher
01/02/2020, 2:23 PMPrateek Grover
01/02/2020, 2:23 PMThomas
07/06/2020, 9:39 AMtl;dr to avoid freezing the continuation, you wait and delay in the current thread/coroutine for the result to be posted from your bg thread into an atomic varHi @basher, thanks for the solution, it really helped me! Do you know if this is still the best way to prevent freezing because of all the changes in
native-mt
?basher
07/06/2020, 1:14 PMThomas
07/06/2020, 2:14 PMsuspendCancellableCoroutine
with native-mt and the continuation appears to already be frozen (at least in my testing code)