A timer schedules a message for later delivery without making an actor wait. The actor continues processing its mailbox while the delay runs, so delayed work fits the same message-driven flow as ordinary commands. section 2.5
For a one-off action, create timers with `Behaviors.withTimers` and call `startSingleTimer` with the message and a `FiniteDuration` delay. The scheduled message must belong to the actor protocol; Scala duration syntax allows values such as `t.second`. section 2.5
Reactivate a wallet later
A wallet handles `Deactivate(seconds)` by scheduling its private `Activate` command, then switches to its deactivated behavior. `Activate` cannot be sent by outside actors, keeping automatic reactivation as internal protocol behavior. After three seconds, the application output shows the activation message arriving. section 2.5
Timers can also enforce a bounded validation window. When a bet opens, it starts a 10-second timer for `ValidationsTimedOut`, persists the opening event, requests market and funds validation, and later handles the timeout only while the bet remains open. section 12.1.3
Use a timer when delayed work should remain explicit in the actor protocol:
- Schedule a private self-message for lifecycle actions such as wallet reactivation. section 2.5
- Schedule a deadline message while asynchronous validations proceed through ordinary commands and events. section 12.1.3
- Keep delayed-message handling state-specific, as `ValidationsTimedOut` is handled in `OpenState`. section 12.1.3
Listing 2.9 activated behavior from WalletTimer
import scala.concurrent.duration._
object WalletTimer {
...
def activated(total: Int): Behavior[Command] =
Behaviors.receive { (context, message) =>
Behaviors.withTimers { timers => #1
message match {
case Increase(amount) =>
val current = total + amount
context.log.info(s"increasing to $current")
resume(current)
case Deactivate(t) =>
timers.startSingleTimer(Activate, t.second) #2
deactivated(total)
case Activate =>
Behaviors.same
}
}
}
}
Inspect the minimal wallet behavior: timer setup sits beside normal message matching, and deactivation schedules `Activate` before returning the deactivated behavior. section 2.5



