Hi, I have the following suspended function, which...
# coroutines
a
Hi, I have the following suspended function, which I want to expose as Java APIs(blocking) and Kotlin API(non-blocking) with same method name.
Copy code
suspend fun getStoreMapping(country: String): List<Store> {
    return client.getStoreMapping(country).stores
}
Currently, the only option I have is to use different method name, which calls the suspended function in
runBlocking {}
like below -
Copy code
fun getStoreMappingInJava(country: String): List<Store> {
    return runBlocking { client.getStoreMapping(country).stores }
}
o
you might be able to add
@JvmName
to the second one and have that work
that way, the kotlin names are different, but since the jvm signature is different, the compiler will let you name it the same thing
https://pl.kotl.in/q2J8Y2uBe appears to compile
Copy code
public final class TestKt {
  public static final java.lang.Object suspender(kotlin.coroutines.Continuation<? super kotlin.Unit>);
  public static final void suspender();
}
looks good to me
g
I prefer to call such functions with Blocking suffix to make it explicit that function will block caller thread
a
It would probably be more useful to expose a future, or callbacks, or Rx Single/Maybe for java callers so that they don't have to block a thread
a
Thanks all for the input 🙂 .