Giter Club home page Giter Club logo

vertx-lang-kotlin's Introduction

Vert.x for Kotlin

Build Status (5.x) Build Status (4.x) GitHub license Kotlin version badge Coroutines version badge

This is the repository for Kotlin language support for Vert.x.

The following modules are available in this project:

  • vertx-lang-kotlin contains extension functions for the majority of Vert.x libraries.

  • vertx-lang-kotlin-coroutines contains coroutines support for Vert.x.

Contributing

Extending Vert.x for Kotlin

Kotlin’s extensions are developed in this directory.

For instance vertx-core extensions are in the io.vertx.kotlin.core package, etc…​

Extensions needs to be tested and documented.

Bumping Kotlin version

There are a couple of rules to follow before increasing the project versions:

  • If changing one between kotlin and kotlinx.coroutines version, make sure that all transitive dependencies, like kotlin-stdlib, still match between the two versions.

Kotlin evolves fast, so just change the project versions, test it, and shot a PR.

vertx-lang-kotlin's People

Contributors

afloarea avatar aguibert avatar alexeysoshin avatar billyyccc avatar cyber-barrista avatar dualscyther avatar enzogalarza avatar gmariotti avatar jo5ef avatar jponge avatar kostya05983 avatar markmarkymarkus avatar mkobit avatar mystdeim avatar okou19900722 avatar pk-work avatar pmlopes avatar rgmz avatar ruslansennov avatar slinkydeveloper avatar tim-britton avatar tomfi avatar tsegismont avatar ultranium avatar vietj avatar vincentfree avatar wowselim avatar yektadev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vertx-lang-kotlin's Issues

Erroneous code example in docs

The following code on this page seems to be broken (I guess it was intended to contain a obj function call):

// The json builder declares a JSON structure
val result = json {
  "firstName" to "Dale",
  "lastName" to "Cooper",
  "age" to 64,
  "names" to array("Dale", "Bartholomew")
}

On another note, the example

// The json builder declares a JSON structure
val result = json {

  // in this structure the array function can be used

  // takes a vararg of values
  array("1", "2", "3")

  // or an iterable of values
  array((1..3).map { "$it" })

  // apply function on array receiver
  array {
    for (i in 1..3) {
      add("$i")
    }
  }
}

is slightly confusing to me, as it is not clear that only the last array{} function will actually have an impact on the json builder. As a kotlin beginner, I expected the result of the json builder to be ["1","2","3","1","2","3","1","2","3"], instead of ["1","2","3"]. Is this correct?

Provide an awaitBlocking function for specific context

In issue #42 a new function was added for running blocking code on the worker pool and as a coroutine.

However, the function calls executeBlocking internally using Vertx.currentContext(). This is problematic for the following reasons:

  1. It make this function less modular and reusable, since it depends on global state
  2. It does not allow control for the developer on which context to run the code
  3. It causes problems in testing since it will always return null because the test code does not run on the event loop.

On the other hand, executeBlocking does allow control on which context to run. awaitBlocking is somewhat a flavor of executeBlocking which works without the need to provide a future, so there's no reason it won't mirror executeBlocking functionality.

Kotlin dataobject generated functions do not handle `JsonObject` only constructor very well

In the case the dataobject only has a JsonObject constructor and no other, along with no way to set properties other than by JsonObject, we generate a helper function like:

fun SomeDataObject() = io.vertx.bla.bla.SomeDataObject(JsonObject())

so it passes in empty JsonObject and then you can never set any of the properties. This should generate:

fun SomeDataObject(block: JsonObject.() -> Unit)
    ): SomeDataObject  {
        io.vertx.codegen.testmodel.SomeDataObject(Json.obj(block))
}

so that the JSON can be built. Or these should be omitted.

It isn't clear how we can tell from the template parameters if this case exists. We cannot see what constructors are available, we cannot tell which properties are public/private and really determine which model should be used. I think in the case of only this one constructor we have to assume that things can only be set by JSON and therefore do the special case (the function above that makes a JSON builder), although we have to be sure they import vertx-kotlin-common dependency and import statements to do that builder. Or we accept JsonObject and they manually call the builder themselves inline.

using codegen with suspend keyword

Hi, I'm quite new to Vert.x so I apologize if the question was already answered somewhere else:
I'm trying to use vertx-codegen in combination with kapt to generate a Proxy of this interface:

@ProxyGen
interface WikiDatabaseService {

    @Fluent
    suspend fun fetchAllPages(resultHandler: Handler<AsyncResult<JsonArray>>): WikiDatabaseService
}

However, the kaptKotlin task fails with the error

w: warning: No SupportedSourceVersion annotation found on io.vertx.serviceproxy.ServiceProxyProcessor, returning RELEASE_6.
w: warning: Supported source version 'RELEASE_6' from annotation processor 'org.jetbrains.kotlin.kapt3.ProcessorWrapper' less than -source '1.8'
e: /Users/guido.mariotti/Documents/IntelliJIDEAProjects/vertx-kotlin-examples/build/tmp/kapt3/stubs/main/com/thegmariottiblog/wiki/database/WikiDatabaseService.java:11: error: Could not generate model for com.thegmariottiblog.wiki.database.WikiDatabaseService#fetchAllPages(io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.json.JsonArray>>,kotlin.coroutines.experimental.Continuation<? super com.thegmariottiblog.wiki.database.WikiDatabaseService>): Handler<AsyncResult<T>> must be the last parameter if present in a proxied method
    public abstract java.lang.Object fetchAllPages(@org.jetbrains.annotations.NotNull()

my understanding, reading the discussion at avoid-extra-continuation-parameter-in-suspending-function, is that the kotlin compiler puts a Continuation<WikiDatabaseService> at the end of the method, that codegen doesn't like.

Is this a known compatibility issue of coroutines? Are there any workaround available or some options to kapt that I'm missing?

Force Vertx Rx CodeGen To Generate MayBe As Return Type(Kotlin)

I am using following Kotlin code to generate proxy (This will also generate Rx methods)

@ProxyGen
@VertxGen
interface JobService {
    @Fluent
    fun getCertain(jobId: Int, handler: Handler<AsyncResult<Job?>>): JobService
}

When I see generated Rx Code it is as follows.

public Single<Job> rxGetCertain(int jobId) { 
   return new io.vertx.reactivex.core.impl.AsyncResultSingle<Job>(handler -> {
     getCertain(jobId, handler);
   });
}

Issue:-

Unfortunately i am not able to use this in Kotlin as kotlin won't allow null values for non-null fields and it is throwing following exception.

java.lang.IllegalArgumentException: Parameter specified as non-null is null

How do i force Vertx CodeGen to generate return type as MayBe so that my code works without any issues in kotlin.

Note: I have tried adding @nullable but no use

i have added Sample Project Here

https://github.com/c-nnooka/VertxCodeGenMayBe

Add Testing Guide

With Vert.x there is no testing guide for Kotlin. Currently if Vert.x testing is done using Kotlin then JUnit and vertx-unit are used for testing, which isn't Kotlinic (idiomatic Kotlin). Kotlin has two main testing frameworks which are Kotlinic: Kotlin Test and Spek.

A Kotlin testing guide would use one of the major testing frameworks. Kotlin Test would be the recommended one to use since it is easy to deploy (can use Gradle via Gradle Kotlin DSL), does testing in a Kotlinic way, and supports multiple testing types (known as testing styles). This GitHub repository provides some insight into how to approach Vert.x testing using Kotlin and Kotlin Test.

JsonObject,mapTo no support data class

I got this data class

data class User(
  val Id: ObjectId,
  var Phone: String,
  var Name: String = "",
  var Gender: String = ""
)

when use JsonObject.mapTo(User::class.java), got Error
java.lang.IllegalArgumentException: Cannot construct instance of User (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3738)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3656)
at io.vertx.core.json.JsonObject.mapTo(JsonObject.java:105)

it's sames error from jackson , and I found https://github.com/FasterXML/jackson-module-kotlin may fix this,will it be updated ?

kotlin version

3.5.1-SNAPSHOT will ship with version 1.2.20 of kotlin. see #44
Latest version as of today is 1.2.21.

It would be great if we were able to specify the kotlin version in our projects.
Right now, I am excluding kotlin dependencies from vertx-lang-kotlin:

compile(group = "io.vertx", name = "vertx-lang-kotlin", version = vertx_version) {
exclude(group = "org.jetbrains.kotlin")
}

Will this lead to incompatibilities, or is this is a reasonable way to keep kotlin version up to date?

Generate DataObject from Kotlin Class

I want to generate a data object from a kotlin class (Author), but it generates an error that I could not solve

Could not generate element for org.vult.services.Author: null

I think it may be because when generating the kotlin stub add annotations to the attributes and thus error in the generation of the converter.

EJ. @org.jetbrains.annotations.NotNull()

it is possible to generate from a kotlin class or is there an example?

This is my Gradle.Script

buildscript{
    ext.kotlin_version = '1.1.3-2'
    ext.shadow_version = '2.0.1'

    repositories{
        jcenter()
    }
    dependencies{
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.github.jengelman.gradle.plugins:shadow:$shadow_version"
    }
}

apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.github.johnrengelman.shadow'

ext.vertx_version = '3.4.2'

repositories {
    jcenter()
}

dependencies {
    implementation "io.vertx:vertx-core:$vertx_version"
    implementation "io.vertx:vertx-web-client:$vertx_version"
    implementation "io.vertx:vertx-rx-java:$vertx_version"
    implementation "io.vertx:vertx-service-proxy:$vertx_version"
    implementation "io.vertx:vertx-codegen:$vertx_version"
    implementation "io.vertx:vertx-lang-kotlin:$vertx_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains:annotations:13.0"
    kapt "io.vertx:vertx-service-proxy:$vertx_version:processor"

    testImplementation 'junit:junit:4.12'
}

compileKotlin{
    kotlinOptions.jvmTarget = "1.8"
}

kapt{

}

sourceSets {
    main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")]
}

Author.kt

@DataObject(generateConverter = true)
class Author(){

    lateinit var name:String
    lateinit var email:String

    constructor(json:JsonObject?):this(){}

    fun toJson():JsonObject{
        val json =  JsonObject()
        return json
    }
}

thanks

Use embeddable kotlin compiler

Currently we use org.jetbrains.kotlin:kotlin-compiler which contains Guava classes. There is an embeddable version org.jetbrains.kotlin:kotlin-compiler-embeddable which shades them

Compilation exceptions when increasing Coroutines to 0.24.0

When updating the project to use Kotlin 1.2.61 or coroutines 0.24.0, the following compilation errors occur

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building vertx-lang-kotlin-coroutines 3.6.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ vertx-lang-kotlin-coroutines ---
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ vertx-lang-kotlin-coroutines ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ vertx-lang-kotlin-coroutines ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- kotlin-maven-plugin:1.2.51:compile (default) @ vertx-lang-kotlin-coroutines ---
[WARNING] Source root doesn't exist: /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/kotlin
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/examples/Example.kt: (91, 58) Type mismatch: inferred type is ReceiveChannelHandler<Message<Int>> but Handler<Message<Int!>!>! was expected
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (43, 39) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (46, 20) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (46, 30) Cannot infer a type for this parameter. Please specify it explicitly.
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (75, 40) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (129, 84) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (135, 44) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (136, 41) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (139, 29) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (146, 25) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (176, 3) 'handle' overrides nothing
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (348, 49) Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (358, 47) Type mismatch: inferred type is VertxScheduledFuture but Handler<Long!>! was expected
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt: (373, 3) 'handle' overrides nothing
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.670 s
[INFO] Finished at: 2018-09-25T19:43:31+02:00
[INFO] Final Memory: 54M/773M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.51:compile (default) on project vertx-lang-kotlin-coroutines: Compilation failure: Compilation failure:
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/examples/Example.kt:[91,58] Type mismatch: inferred type is ReceiveChannelHandler<Message<Int>> but Handler<Message<Int!>!>! was expected
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[43,39] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[46,20] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[46,30] Cannot infer a type for this parameter. Please specify it explicitly.
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[75,40] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[129,84] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[135,44] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[136,41] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[139,29] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[146,25] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[176,3] 'handle' overrides nothing
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[348,49] Unresolved reference: Handler
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[358,47] Type mismatch: inferred type is VertxScheduledFuture but Handler<Long!>! was expected
[ERROR] /Users/guido.mariotti/Documents/GitHub/vertx-lang-kotlin/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt:[373,3] 'handle' overrides nothing
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

However, IntelliJ doesn't flag any of them, so my guess is that probably some maven plugin is causing it. Any idea which one of them?

Provide Kotlin JS Library For vertx-sockjs-service-proxy

Vert.x provides Sock JS Service Proxy libraries (for Java, Kotlin JVM, JS etc) however there isn't one available for Kotlin JS (video). Kotlin covers both server-side (using Kotlin JVM or Kotlin JS) and web front-end (Kotlin JS only at the moment) development, which means it can be used to develop full stack web apps (Thinkter sample, Kotlin Conf app). By providing a Kotlin JS library it enables a Kotlin JS app (web front-end) to easily communicate with a Vert.x app (server-side) through asynchronous message passing via Web Sockets, which should in theory be type safe with straightforward interop.

In order to have the Kotlin JS lib developed the following is needed:

  • Access to the Vert.x Sock JS Service Proxy lib source code
  • Reference documentation for Vert.x Sock JS Service Proxy lib
  • Type information on Vert.x Sock JS Service Proxy lib APIs

If the Kotlin JS lib is going to be developed then it would be highly advisable to structure the lib as part of a Kotlin multi-platform project (video). Kotlin Native (overview video, Kotlin Conf 2017 video) which is under development has experimental WASM support (refer to the HTML 5 Canvas sample), which allows the technology to be used as an alternative for web front-end development. Most major web browsers (incl the mobile ones) officially support WASM.

Wrong vertx-lang-kotlin-coroutines name in docs

In the documentation (e.g. index.adoc file) the vertx-lang-kotlin-coroutines module is always indicated as vertx-lang-kotlin-coroutine (without the the 's' at the end) creating lots of confusion when you try to import it in your project.

Link to extension directory is broken

The README contains broken links for the extension source code and documentation directories.

Kotlin extensions are developed in this directory.

404: https://github.com/vert-x3/vertx-lang-kotlin/blob/master/vertx-lang-kotlin/src/main/java/io/vertx/kotlin

Extensions needs to be tested and documented.

404: https://github.com/vert-x3/vertx-lang-kotlin/blob/master/vertx-lang-kotlin/src/main/asciidoc/index.adoc


I can't seem to find an equivalent directory — where should extensions now go?

Integrate classes from https://github.com/cy6erGn0m/vertx3-lang-kotlin

Hi, thanks for this great Korlin integration.

However, I still notice that https://github.com/cy6erGn0m/vertx3-lang-kotlin, there are some classes (i.e. AsyncResult) that are still not available when just using this module. I need to include both vertx3-lang-kotlin and vertx-lang-kotlin to get the most out of Kotlin-style integration. The readme in https://github.com/cy6erGn0m/vertx3-lang-kotlin says that

vertx3-lang-kotlin is going to be moved into vert.x organization: https://github.com/vert-x3/vertx-lang-kotlin/

But it has been like that for a very long time now. Is there any plan to do such thing at all ? That would be superb.

Thank you.

add suspend functions for Vertx coroutine usage

I think that is useful for coroutine usage like some functions below:

suspend fun Vertx.adelay(ms:Long) = awaitEvent<Long> { setTimer(ms, it) }
suspend fun Vertx.adeploy(verticle: Verticle, option:DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticle, option, it)
}
suspend fun Vertx.adeploy(verticle:String, option: DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticle, option, it)
}
suspend fun Vertx.adeploy(verticleSupplier:Supplier<Verticle>, option: DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticleSupplier, option, it)
}
suspend fun <T:Verticle> Vertx.adeploy(verticleClass: Class<T>, option: DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticleClass, option, it)
}
suspend fun Vertx.aundeploy(deployId:String) = awaitResult<Void> {
    undeploy(deployId, it)
}
suspend fun <T> Vertx.arunBlocking(order:Boolean = true, block:()->T) = awaitResult<T> {
    executeBlocking(Handler<Future<T>> { f ->
        try {
            f.complete(block())
        } catch (e:Throwable) {
            f.fail(e)
        }
    }, order, it)
}

if needed, I can make a PR for these kind of extensions

Replicated Kotlin coroutines function

In this file:

https://github.com/vert-x3/vertx-lang-kotlin/blob/master/vertx-lang-kotlin-coroutines/src/main/java/io/vertx/kotlin/coroutines/VertxCoroutine.kt

The extension method Future.await() is essentially a duplicate of CompletionStage.await() as documented here:

https://github.com/Kotlin/kotlinx.coroutines/blob/master/integration/kotlinx-coroutines-jdk8/README.md

I assume this has happened because CompletionStage.await() was only added in March this year. Should the Vertx version be deprecated in favour of the official Kotlin library method?

Closure interoperability with Handler

Hello,

I'm often finding myself stuck with this kind of stuff :

    @Before
    fun setup(ctx: TestContext) {
        vertx.executeBlocking<Void>( { fut: Future<Void> ->
            // blocking stuff
            fut.complete()
        }, ctx.asyncAssertSuccess())
    }

This code doesn't compile because the first closure cannot be understood as a Handler<Future<Void>>

The compiling equivalent would be :

    @Before
    fun setup(ctx: TestContext) {
        vertx.executeBlocking<Void>( Handler { fut: Future<Void> ->
            // blocking stuff
            fut.complete()
        }, ctx.asyncAssertSuccess())
    }

Is there a way to avoid the Handler { stuff ? Is this a kotlin limitation ?

In every other language, scala included, a lambda is a valid replacement for a Handler can we do something about this ?

Thanks.

How to determine the return value of the suspend method is nullable

I don't know how the TypeInfo.isNullable method is implemented. When I implement codegen, it returns a nullable type, but then you change it to be based on isNullable. Now when I get a non-existent key via redisClient.getAwait(String), the returned type is a non-null type String, causing an exception to be thrown when I call its method. Although I may judge whether it is empty, the compiler will throw a warning.

Investigate usefulness of code generation for Kotlin coroutines

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)

Coroutine suspend generated method naming scheme

Current Kotlin suspend generated method are named with an Await suffix:

vertx.deployVerticle(verticle, Handler { ... }) 

// becomes

val id = vertx.deployVerticleAwait(verticle);

this issue gathers proposal and opinions about the best naming for 3.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.