Sanjay
Sanjay

Reputation: 55

Akka future.await does not return when there is a timeout

I am new to Akka, and am having trouble with the Future.await call in Akka 1.2. I have created some Futures with OnTimeout and OnException handlers, and then I am waiting for them to complete. The code looks something like this:

val futures = ListBuffer.empty[Future[Any]]
val future = (peer ? bMsg) onResult {
      case result => result match {
          case msg:Ack => handleAck(msg)
          case msg:Nack => handleNack(msg)
        }
    } onTimeout {
      case _ => {
          // do something
      }
    } onException {
      case _ => {
          // do something
      }
    }
futures += future

futures.foreach(_.await(Duration(8000, "millis")))
log.info("Got here")

When there is an exception, the exception handler gets executed and I get to the "Got here" line. However, when there is a timeout, though the timeout handler is executed, I never get to the "Got here" line. Even with the AtMost value set, await does not return.

What could be causing this?

Upvotes: 1

Views: 850

Answers (1)

Viktor Klang
Viktor Klang

Reputation: 26579

await throws an exception if it times out, have you've verified that you're not getting an exception in futures.foreach?

Upvotes: 1

Related Questions