score:0

Use scala.concurrent.Await (JavaDoc). Maybe the following sketch is what you are looking for?

import scala.concurrent.Future
import scala.concurrent.ExecutionContext._
import scala.concurrent.duration.Duration
import scala.concurrent.duration._
import scala.concurrent.Await
import java.util.concurrent.Executors.newScheduledThreadPool

object Test {
  implicit val executor = fromExecutorService(newScheduledThreadPool(10))
  val timeout = 30 seconds

  def main(args: Array[String]) {
    val f =
      // Make HTTP request, which yields a string (say); simulated here as follows
      Future[String] {
        Thread.sleep(1000)
        "Response"
      }.
        // Read input
        map {
          response =>
            println("Please state your problem: ")
            val ln = readLine() // Note: this is blocking.
            (response, ln)
        }.
        // Futher processing
        map {
          case (response, input) =>
            println("Response: " + response + ", input: " + input)
        }
    Await.ready(f, timeout)
  }
}

Related Query

More Query from same tag