ninja icon indicating copy to clipboard operation
ninja copied to clipboard

documentation: how does async work?

Open raphaelbauer opened this issue 12 years ago • 3 comments

raphaelbauer avatar Aug 18 '12 12:08 raphaelbauer

Any updates on this topic?

s4gh avatar Oct 05 '13 11:10 s4gh

Docu is not yet there, but the integration test has a class that can serve as an example: https://github.com/ninjaframework/ninja/blob/develop/ninja-servlet-integration-test/src/main/java/controllers/AsyncController.java

Please feel free to add any documentation. Ninja is a community project and all help is well appreciated :)

raphaelbauer avatar Oct 05 '13 16:10 raphaelbauer

I just did some testing with async for the first time in ninja and noticed the following: I need to call context.handleAsync() before returning Results.async(); for it to work, otherwise the client gets an empty http reply immediately (before I called returnResultAsync). Is this the expected behavior? I saw that handleAsync() is called internally as well when calling retrunResultAsync so I'm not sure if this is the correct usage.

Update: I'm also getting some IllegalStateException: s=IDLE i=true a=NOT_ASYNC when processing some requests although the client is still waiting for a reply (tcp connection not closed).

A bit of background information: For some endpoints I need to limit the number of parallel executions without blocking the threads. My idea was to put the requests into a queue and return Results.async(). A single worker thread then processes the queue and returns the result with context.returnResultAsync. This seems to work for 70% of the requests, but for the others I get the exception mentioned above when calling returnResultAsync.

Any idea?

davidgiga1993 avatar Jan 28 '21 07:01 davidgiga1993