#2612 - Clarifying ReceiveTimeout semantics in the documentation.

This commit is contained in:
Viktor Klang 2012-10-14 03:35:09 +02:00
parent b193a45235
commit 0ab417b2c1
4 changed files with 39 additions and 14 deletions

View file

@ -549,13 +549,20 @@ defaults to a 'dead-letter' actor ref.
val result = process(request)
sender ! result // will have dead-letter actor as default
Initial receive timeout
=======================
Receive timeout
===============
A timeout mechanism can be used to receive a message when no initial message is
received within a certain time. To receive this timeout you have to set the
``receiveTimeout`` property and declare a case handing the ReceiveTimeout
object.
The `ActorContext` :meth:`setReceiveTimeout` defines the inactivity timeout after which
the sending of a `ReceiveTimeout` message is triggered.
When specified, the receive function should be able to handle an `akka.actor.ReceiveTimeout` message.
1 millisecond is the minimum supported timeout.
Please note that the receive timeout might fire and enqueue the `ReceiveTimeout` message right after
another message was enqueued; hence it is **not guaranteed** that upon reception of the receive
timeout there must have been an idle period beforehand as configured via this method.
Once set, the receive timeout stays in effect (i.e. continues firing repeatedly after inactivity
periods). Pass in `Duration.Undefined` to switch off this feature.
.. includecode:: code/docs/actor/ActorDocSpec.scala#receive-timeout

View file

@ -269,11 +269,18 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
//#receive-timeout
import akka.actor.ReceiveTimeout
import scala.concurrent.util.duration._
import scala.concurrent.util.Duration
class MyActor extends Actor {
// To set an initial delay
context.setReceiveTimeout(30 milliseconds)
def receive = {
case "Hello" //...
case ReceiveTimeout throw new RuntimeException("received timeout")
case "Hello"
// To set in a response to a message
context.setReceiveTimeout(30 milliseconds)
case ReceiveTimeout
// To turn it off
context.setReceiveTimeout(Duration.Undefined)
throw new RuntimeException("Receive timed out")
}
}
//#receive-timeout