lundi 20 avril 2015

Either wait for a function to finish or timeout after 5 seconds in Akka

I'm trying to wait for a function to finish or timeout after 5 seconds, but whatever I do, I can't prevent the following exception. Interestingly it is caught by the parent actor:

java.util.concurrent.TimeoutException: Futures timed out after [5 seconds]

One of the solutions that I tried (from this question):

val f = Future { dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec() }
val result: Try[InputStream] = Await.ready(f, 5.seconds).value.get

val resultEither = result match {
  case Success(t) => log.info("right")
  case Failure(e) => log.info("left")
}

Aucun commentaire:

Enregistrer un commentaire