in this post Angular.js with Scalatra it is said that the http call is asynchronous. I see that the call to the actor is done with:
myActor ? q
however in scalatra home page i see they encapsulate the call with AsyncResult see:
get("/"){
new AsyncResult { def is =
Future {
// Add async logic here
<html><body>Hello Akka</body></html>
}
}
}
is there a difference between the two? I understand that the first one is calling an actor which returns a future, does that mean that both calls are async?
can you elaborate a little more about how the synchronicity of
get("/query/:key/:value") {
contentType = formats("json")
val q = Query(params("key"), params("value"), mongoColl)
myActor ? q
}
is the http thread released?
Both calls are async. 'get' will either return a result or timeout. The request will wait for some kind of reaction from the Actor in this case however.
The application will not lock up if a result is not returned because of the protected implicit val timeout = Timeout(10)
at the top of the class (this will instruct myActor ? q
to give up on a result after 10 seconds).
The second example is a pure future based approach in which the body of 'Future' performs a series of operations async and onComplete returns a result.
I suggest you read Akka Actors documentation for more details