Florent Dambreville
05/09/2022, 12:45 PM1.6.20
and I get a crash when calling a suspendCoroutine
function :
var topupCountries: Deferred<Set<String>> = buildCountriesAsync()
private set
private fun buildCountriesAsync() = CoroutineScope(backgroundDispatcher).async(start = CoroutineStart.LAZY) {
getCountries()
}
private suspend fun getCountries(): Set<String> {
return try {
topupCountries.getCompleted()
} catch (exception: IllegalStateException) {
// Crash here
fetchRestrictedTopupCountries()
} }
private suspend fun fetchRestrictedTopupCountries(): Set<String> {
return suspendCoroutine { continuation ->
val request = ApiTopupRequestFactory.getTopupCountries(
listener = {
val setResult = it.countries.toSet()
continuation.resume(setResult)
},
errorListener = {
continuation.resume(setOf())
}
)
execute(request)
}
}
The error is : java.lang.ClassCastException: kotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to java.util.Set
Am I doing something wrong here ? Anyone else with this issue ?Florent Dambreville
05/09/2022, 12:45 PMFlorent Dambreville
05/09/2022, 12:46 PMinline
and crossinline
usageFlorent Dambreville
05/09/2022, 12:48 PMsuspendCoroutine
uses thoses two :
suspend inline fun <T> suspendCoroutine(
crossinline block: (Continuation<T>) -> Unit
): T
Florent Dambreville
05/09/2022, 1:02 PMgetCompleted
function is not meant to be used like that