ninja
ninja copied to clipboard
documentation: how does async work?
Any updates on this topic?
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 :)
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?