Search code examples
scalaakkaactor

Akka Actor - wait for some time to expect a message, otherwise send a message out


Is it possible to make an Actor wait for X amount of seconds to receive any message, and if a message is received, process it as usual, otherwise send a message to some other Actor (pre-determined in the constructor)?


Solution

  • Yes, if you want to wait for any message, you simply set a receiveTimeout: http://doc.akka.io/docs/akka/current/scala/actors.html#receive-timeout

    (The docs is slightly misleading here, you can set the receiveTimeout after every message also)