hey guys, if you invoke a kotlin suspend fun via j...
# coroutines
g
hey guys, if you invoke a kotlin suspend fun via java reflection, it looks to me like theres no way for the reflective caller to differentiate between the function having been suspended and the function compelting without suspension ie:
Copy code
suspend fun foo(): Unit {
  //noop
}

suspend fun bar(): Unit {
  yield()
}

...
fun main(){
  val fooReflect: java.lang.Method = makeJavaMethod(::foo)
  val barReflect: java.lang.method = makeJavaMethod(::bar)

  runBlocking {
    suspendCoroutineUnit> { cont -> 
      val fooResult = fooReflect.invoke(instance, cont)
      // fooResult is null, and foo doesnt yield, so i need to call cont.resume(Unit) here..
    }
    suspendCoroutineUnit> { cont -> 
      val barResult = barReflect.invoke(instance, cont)
      // BarResult is null, but bar does yield, so I cant call cont.resume(Unit) here!
    }
  }
}
how can i tell based on the
java.lang.Method
and its
invoke
return value, if I need to call
resume
?
j
It will return COROUTINE_SUPENDED
g
@jw that's what I first thought but I was wrong, both fooMethod and barmethod return null.