Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! framework with missing type Promise

I'm trying to get my first Scala + Play! application working, and I encounter this problem when trying to access my application (on port 9000) :

not found: type Promise

on this line:

val page: Promise[play.api.libs.ws.Response] = WS.url(googleApiUrl).get() 

Those are my imports:

import play.api._
import play.api.mvc._
import play.api.libs.ws._
import play.api.libs.ws.Response
import play.api.http
import play.api.libs.concurrent._
import play.api.libs._

Am I missing something here ?

Those are logs on the console:

sbt.PlayExceptions$CompilationException: Compilation error[not found: type Promise]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:322) ~[na:na]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:322) ~[na:na]
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:322) ~[na:na]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:319) ~[na:na]
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
like image 558
wlk Avatar asked Dec 27 '22 12:12

wlk


1 Answers

Play2.1 use Scala Future instead of play Promise.

Check the migration guide for more informations, chapter "Play's Promise to become Scala's Future".

A simple exemple give something like that :

import play.api._
import play.api.mvc._
import play.api.libs.ws._

import play.api.libs.concurrent._
import play.api.libs.concurrent.Execution.Implicits._

def myAction() = Action {
    Async {
        WS.url(googleApiUrl).get.map(response => Ok("what you want here"))
    }
}

You can check this exemple with a more complexe use of WS api.

like image 82
Julien Lafont Avatar answered Jan 15 '23 15:01

Julien Lafont