preStart() question

When an actor starts up and preStart() is run, is it guaranteed that the actor will not receive any messages via onReceive() until the entire code block in preStart() is run?

The reason I ask is I have some business logic that has to run during initialization and just want to make sure that nothing else in the actor is happening.

Yes, that’s guaranteed. As the name implies “pre start” => “before starting doing other stuff” :-)
If you do any async (futures in preStart though) it will not wait for them to complete ofc.

1 Like

From here:
seems pretty definitive:

The Akka actor API exposes many lifecycle hooks that you can override in an actor implementation. The most commonly used are preStart() and postStop().

preStart() is invoked after the actor has started but before it processes its first message.
postStop() is invoked just before the actor stops. No messages are processed after this point.
1 Like