2

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?

Jas
  • 14,493
  • 27
  • 97
  • 148

1 Answers1

1

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

JohnStrong
  • 26
  • 1
  • Hi in myActor ? Is there any blocking? I understand from akka side no blocking but is there a blocking of a thread from scalatra side? Or in other words is the new syncResult required In case of calling an actor with the above `?` notation? – Jas Oct 18 '13 at 08:12