For people interested in what’s doing the Kotlin c...
# coroutines
m
For people interested in what’s doing the Kotlin compiler under the hood 👌 Blog post about this coming along next week

https://www.youtube.com/watch?v=IQf-vtIC-Uc&list=PLWz5rJ2EKKc_T0fSZc9obnmnWcjvmJdw_&index=5

💪 1
👍 8
s
The return type of the transformed function is actually
Any?
, not
Unit
, right?
m
It’s
Unit
, there’s nothing to return
the
completion
param is used to “return” a value
s
Have you checked https://jakewharton.com/exceptions-and-proxies-and-coroutines-oh-my/#coroutine-implementation-crash-course ?
completion
seems not the only way to "return" value...
m
Wonder if it’s because of the use of
suspendCoroutine
s
I believe @elizarov explained it in this talk before:

https://youtu.be/3xalVUY69Ok

, but I can't find the slide now...
j
All suspend functions use
Any?
as a return type because it's a union type of
T | COROUTINE_SUSPENDED
👍 1
This allows code like
Copy code
suspend fun foo(): String {
  return if (Random.nextBoolean()) {
    4
  } else {
    otherSuspendFunction()
  }
}
to return synchronously when it can. Synchronous exceptions behave similarly.
❤️ 1
m
Thanks @jw! Will add that to the the post 👌
a
I have an example of calling suspend functions from Java at https://github.com/araqnid/library-versions/blob/master/java/src/main/java/org/araqnid/libraryversions/java/JavaMain.java which illustrates the call interface, if it’s helpful