It’s also considered good form to shut the ActorSystem down when you’re done
with it. Keep in mind that a servlet context destroy does not necessarily mean
a full application shutdown, it might be a reload - so you’ll need to release
the ActorSystem resources when your Scalatra application is destroyed.

Using Scala Futures

Scalatra’s FutureSupport trait provides a mechanism for adding Futures
to your routes. At the point where you

AsyncResult isn’t strictly necessary. It’s a way to ensure that if you close your
Future over mutable state (such as a request object or a var) that the state is
captured at the point you hand off to the Future.

If you attempt to use mutable
state inside your Future without AsyncResult (e.g. calling request.headers or something),
you’ll get an exception. If you use AsyncResult, it’ll work. So, you’re trading a bit
of boilerplate code for a bit of safety. If you can remember not to close over mutable
state, don’t bother with AsyncResult.

Actor example

See
akka-examples
for a minimal and standalone project containing the examples in this guide.

When you use Scalatra with Akka, you most likely want to return a result of some sort. So you’re probably going to send a message to an Actor which will reply to you. The method you use for that returns a Future. Typically, this involves Akka’s ask pattern.