liveBook · Manning

Timeout

As explained in Akka in Action, Second Edition

Timeout is an Akka value that represents the maximum duration allowed for an asynchronous operation before it is treated as timed out.

Timeout is the Akka value that sets how long an actor will wait for a reply when using the ask pattern. An ask has two outcomes: a reply arrives in time and is handled as Success, or no timely reply arrives and is handled as Failure. section 3.2 section 3.4

Set a timeout wherever an ask needs a response deadline. In Scala, `Timeout(3, SECONDS)` can be supplied to `context.ask`; the ask signature accepts it as the implicit `responseTimeout` argument, so an implicit value in scope can be selected automatically. section 3.2.4 section 3.2.7

Parsing worker with a three-second deadline

A manager creates a worker, asks it to parse text, and maps `Success(Worker.Done)` to a successful report and `Failure(ex)` to a failure report. With a three-second timeout, a worker that finishes too late can still complete its work, but its response is no longer useful to the asking workflow. section 3.2.4 section 3.2.1

A timeout does not establish reliable delivery or cancel the worker’s work. The ask uses an ephemeral proxy actor as the reply target; when its time expires, it reports an error and stops. A later worker reply can then be forwarded to dead letters. Sending to dead letters is best effort with at-most-once delivery. section 3.2.1

Figure 3.6 Ephemeral intermediate actor lifespan and duties after a timeout
CH03_F06_Abraham2

The diagram shows the short-lived intermediate actor that receives the worker reply, times out the ask, and stops before a late reply can arrive. section 3.2.1

When choosing and handling a timeout:

  • Treat it as the maximum wait for the response, not as proof that the worker stopped or failed. section 3.2 section 3.2.1
  • Handle both `Success` and `Failure` in the response callback, producing a message the manager can process. section 3.2.4 section 3.2.7
  • Expect a timeout when a recipient does not send a reply, including when worker execution prevents a response. section 3.2.1

How Akka in Action, Second Edition covers it

How deep it goes
Explains timeout through ask callbacks, implicit arguments, proxy lifecycle, and late-message dead letters without detailing Scala implicit scopes.
Examples
Uses a manager asking per-text parsing workers, including a three-second timeout and a late worker reply sent to dead letters.
What it assumes
Introduces Scala implicit values only as needed to supply the ask responseTimeout automatically.
What you can do after
Apply it via ActorContext.ask by supplying a Timeout and mapping timely replies and failures into manager commands.
How it connects
Connects ask to Try, Success, Failure, ActorRef, message adapters, dead letters, and at-most-once delivery.

Also explained in

Compare how 9 books explain timeout →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.