How do I wrap a java.util.concurrent.Future in an Akka Future?

前端 未结 2 1715
时光取名叫无心
时光取名叫无心 2020-12-24 14:56

In a Play Framework 2.0.1 (Scala) application, we are using a web service client library which returns java.util.concurrent.Future as responses.

Instead

2条回答
  •  情歌与酒
    2020-12-24 15:59

    You should use akka.dispatch.Futures.future() with java.util.concurrent.Callable:

    val akkaFuture: akka.dispatch.Future[String] = akka.dispatch.Futures.future(
      new java.util.concurrent.Callable[String] {
        def call: String = {
          return "scala->" + javaFuture.get
        }
    }, executionContext)
    

    Gist for complete example

提交回复
热议问题