Throwing exception in future callback

Does throwing an exception in a Future callback result in the Actor’s suspension (the actor in which the future callback code is). Just want to make sure because technically that code is not necessarily being executed by the main message processing thread and I don’t know if there would be a semantic difference? Thanks for any help!

Future callback code is not executing in the actor, it will be running on the (implicit) execution context you passed when defining it.

You should be really careful with future callbacks in actors, it is very easy to touch internal mutable state by mistake.

Best is not mixing them at all and instead use pipeTo to send the future result to the actor as a message and react on that message, if you can’t do that it is good to move such callback logic to a static method outside of the actor so that it cannot close over actor internals.

1 Like