Matt Groth
05/11/2023, 10:47 PMsuspend fun
could have a class that implements it and converts it to just a regular fun
? The implementing class would simply ignore the suspend
keyword.kevin.cianfarini
05/11/2023, 10:52 PMasync
) generic.
https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-generics.htmlMatt Groth
05/11/2023, 10:58 PMephemient
05/12/2023, 12:31 PMinterface Suspending {
suspend fun get()
}
abstract class Immediate : Suspending {
abstract fun immediate()
final override suspend fun get() = immediate()
}
but the two functions need different names (even though technically their platform signatures don't collide)fun <T> runUndispatched(block: suspend () -> T): T {
val scope = CoroutineScope(Dispatchers.Unconfined)
val deferred = scope.async { block() }
scope.cancel()
return deferred.getCompleted()
}
and as long as block
returns a value without actually suspending, it'll work (otherwise it'll throw)why
05/27/2023, 8:50 AM