Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 2.38 KB

README.asciidoc

File metadata and controls

58 lines (45 loc) · 2.38 KB

Scala Module for Vert.x

Scala language implementation for Vert.x 2.1

Quickstart

To use it, we’ve added a first "Hello World"-like example to the Vert.x Examples repository which can be run like this:

  1. Download Vert.x distribution 2.1-M1 or higher.

  2. Open [VERTX_HOME]/conf/langs.properties file and these lines:

    scala=io.vertx~lang-scala~0.3.0:org.vertx.scala.platform.impl.ScalaVerticleFactory
    .scala=scala
  3. Clone or download the Vert.x Examples Git repository

  4. Change directory to src/raw/scala and type:

    [VERTX_HOME]/bin/vertx run http/Server.scala
  5. Go to http://localhost:8080/ and you should see the message: ""This is a Verticle script!"

Using the Vert.x Scala API

The best places to look for examples on how to use the Vert.x Scala API are the Vert.x Examples repository and the Vert.x Scala testsuite. Please inspect those if you have any doubts. The following sub sections explain some of the items to bear in mind when using this API.

Type annotations for handlers in for overloaded methods

In some cases, the Scala compiler can fail to detect the type of a particular handler, for example:

+

val datagramSocket = vertx.createDatagramSocket()
datagramSocket.send("hello", "127.0.0.1", 1234, { h: AsyncResult[DatagramSocket] =>
   ...
}

+

In this example, send method call explicitly needs to define the type annotation for the async result handler. This is because there’s an overloaded method that sends a org.vertx.scala.core.buffer.Buffer instead of a String.

A possible workaround would have been to use function currying, but doing so would limit the API capability to add scala.concurrent.Future based methods, which are better suited for implementing handlers.