title: ListenableFuture to scala Future
body: <p>I am in the process of writing a small scala wrapper around a java library.</p>
  
  <p>The java library has an object QueryExecutor exposing 2 methods:</p>
  
  <ul>
  <li>execute(query): Result </li>
  <li>asyncExecute(query): ListenableFuture[Result]</li>
  </ul>
  
  <p>ListenableFuture in this context is the one from the guava library.</p>
  
  <p>I want my scala wrapper to return a Future[Result] instead of the java object, but I am not sure what is the best way to implement that. Here are 2 solutions I came up with:</p>
  
  <pre><code>future {
    executor.execute(query)
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>val p = promise[Result]
  val guavaFuture = executor.asyncExecute(query)
  
  Futures.addCallback(guavaFuture, new FutureCallback[Result] {
    def onFailure(t: Throwable) {
      p.failure(t)
    }
  
    def onSuccess(result: Result) {
      p.success(result)
    }
  })
  
  p.future
  </code></pre>
  
  <p>I am wondering which method is the best. My intuition is that the first one, while returning a Future, will still block a thread while the call to execute waits for a response, the second one looks like it should be really non blocking. Any comment on the pros/cons of each method ?</p>