Hi
but it is not better for Kotlin itself (if you design for Kotlin usage)
perhaps I explained it bad, sorry.
My proposal isn’t to modify Kotlin syntax, but bytecode generation, so return a Continuable
instead to add an extra parameters (continue
invocation is syntetized by compiler); in such case we gain better interoperability without modify nothing in Kotlin style.
You can get some explanation as to why it is so for Kotlin in the design docs
I read the document, probabily the affected parts are:
Observe, that async-style function composition is more verbose and error prone. If you omit .await() invocation in async-style example…
Compiler will garantee coroutine’s resume invoking the appropriate methods.
Compare how these styles scale for a big project using many libraries…
Kotlin standard library is another one in the party, using a new proprietary Continuation
doesn’t avoid any extra class definition.
Compare their performance…
This is covered in my Vert.x proposal, but I can suppose that may be really a different context.
Definitely you can evalutate the problem better than me.
Suspending functions look strange from any language that does not support continuation-passing-style natively.
Kotlin supports CPS but I think that invoking a non Kotlin suspending function (eg: Scala function) looks likewise strange (please fix me if I get it wrong).
IMHO the problem is inside the function’s binary signature.
he async and suspending styles can be easily converted into one another using the primitives that we’ve already seen.
So, you can write suspending function in Kotlin just once, and then adapt it for interop with any style of promise/future with one line of code using an appropriate future{} coroutine builder function.
This is the Vert.x problem: write an extra line each time is really hassle; why don’t demand this to compiler?
However, for the purpose of interoperability you can always choose to expose a future.
Nice, but Kotlin interoperates really well with Java, so think twice before propose the bad way as default.
Why don’t return a Future
as default and passing the Continuation
to it?
You can even have both
Yes, I can, but I don’t consider pleasant have both.
I suppose that a main issue is a performance problem, it is a Vert.x team big fear (apart breaking change, but Kotlin has experimental library : )
Maybe a suspending function can produce a state machin implementing both Continuation
and Continuable
interfaces.