One way to do it:
case HttpRequest(GET, Uri.Path("/ping"), _, _, _) => {
val replyTo = sender
Future {
someCPUIntensiveFunction()
replyTo ! HttpResponse(entity = "this is t2")
}
}
Basically, you move the "heavy function" call into a Future. That will make the current thread, which receives the HttpRequest, proceed as soon as it creates the future, and is able to process the next HttpRequest. The future will execute its code in a separate thread. So, you'll have two "paths" in your program. One, which will process HttpRequest, and another which will execute someCPUIntensiveFunction()