Converting Guava futures to Twitter ones

190 views Asked by At

I have a Finatra application that accesses Cassandra using Datastax driver which produces Guava Futures. The conversion is done by following code

import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture}
import com.twitter.util.{Future, Promise}

implicit def toTwitterFuture[A](f: ListenableFuture[A]): Future[A] = {
  val p = Promise[A]()

  val callback = new FutureCallback[A] {
    override def onSuccess(result: A): Unit = p.setValue(result)

    override def onFailure(t: Throwable): Unit = p.setException(t)
  }

  Futures.addCallback(f, callback)
  p
}

Problem is, after this conversion the rest of the request processing happens in a thread pool created by Cassandra driver potentially blocking other I/O tasks. How can I access Finagle's executor where this kind of CPU-intensive work should be done?

0

There are 0 answers