vertx-lang-kotlin icon indicating copy to clipboard operation
vertx-lang-kotlin copied to clipboard

Investigate usefulness of code generation for Kotlin coroutines

Open vietj opened this issue 6 years ago • 7 comments

for instance, now we use the await* suspending function like this

val id = awaitEvent<Long> { vertx.setTimer(1000, it) }

we could generate extensions:

suspend fun Vertx.setTimer(delay: Long): Long {
  return awaitEvent<Long> { setTimer(delay, it) }
}

that allow to directly write:

val id = vertx.setTimer(1000)

vietj avatar Oct 27 '17 14:10 vietj

LGTM :) by the way, the last line is

val id = Vertx.setTimer(1000)

stream-iori avatar Oct 27 '17 16:10 stream-iori

actually no, this is Kotlin and that's an extension method that is available on vertx instances.

vietj avatar Oct 27 '17 18:10 vietj

It's true, my fault. 😅

stream-iori avatar Oct 28 '17 00:10 stream-iori

This would be very preferential. There are many areas that callbacks in vertx api could be translated to coroutine suspension function and IMO would make it more idiomatic kotlin and simpler for those approaching vertx as well.

CoreyKaylor avatar Nov 25 '17 18:11 CoreyKaylor

It is useful if working with coroutine. Is this code generator done by vertx-codegen?

feiyanke avatar Mar 09 '18 03:03 feiyanke

@feiyanke yes, it is currently implemented for data object and Kotlin in this project

vietj avatar Mar 09 '18 08:03 vietj

I have spent the long weekend to come up with this pull request #53 . The code is quite hacky for now though. 😕

Would anyone mind reviewing before I continue?

phiSgr avatar Apr 02 '18 10:04 phiSgr

Closing as outdated, coroutines support has been implemented

tsegismont avatar Dec 08 '22 16:12 tsegismont