tylerwilson
07/31/2024, 2:51 PMCLOVIS
08/01/2024, 7:37 AMsuspend
until the function finishes.tylerwilson
08/01/2024, 12:57 PMapiCall(param1, param2) { success, exception ->
}
note it is not defined as suspend. So I just need to know how I can "suspend until the function finishes".CLOVIS
08/01/2024, 1:05 PMsuspend
:
suspend fun apiCallSync(param1: …, param2: …): T {
return suspendCoroutine { cont ->
apiCall(param1, param2) { success, exception ->
if (success != null) cont.resume(success)
else cont.resumeWithException(exception)
}
}
}
tylerwilson
08/01/2024, 1:21 PMCLOVIS
08/01/2024, 1:30 PMCLOVIS
08/01/2024, 1:32 PMsuspendCancellableCoroutine
is better