scala - preStart hook: a message to the actor itself -
let's override prestart
hook , send message self
:
class someactor extends actor { override def prestart(): unit = { self ! somemessage } ... }
can expect somemessage
first message in queue?
no, since actor creation happens asynchronously might have enqueued message before constructor or prestart
run. if need ensure processing of message before other you’ll need use become
, stash
:
self ! somemessage def receive = initial def initial: receive = { case somemessage => // stuff unstashall() context become initialized case _ => stash() } def initialized: receive = { // normal behavior }
you’ll need mix in akka.actor.stash
trait , configure actor use dequebasedmailbox
.
Comments
Post a Comment