Async does not return the result body
See original GitHub issueThe “async” does return the set status code, but not the body. The provided example does not checks that.
I have provided an updated example (see link below) where I do set a body for the 2 examples already provided by javalin
and also added 2 examples using a real life async scenario: obtaining the data from a service that returns a CompletionStage
(or CompletableFuture
).
From that example, we can observe the following results.
/test-custom
$ http http://localhost:5454/test-custom
HTTP/1.1 418 I'm a Teapot
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Date: Thu, 09 Nov 2017 10:57:19 GMT
Server: Javalin
Body is empty.
/test-async
$ http http://localhost:5454/test-async
HTTP/1.1 418 I'm a Teapot
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Date: Thu, 09 Nov 2017 10:57:56 GMT
Server: Javalin
Body is empty.
/test-future
Run 1
$ http http://localhost:5454/test-future
HTTP/1.1 418 I'm a Teapot
Content-Length: 13
Content-Type: text/plain;charset=utf-8
Date: Thu, 09 Nov 2017 10:58:50 GMT
Server: Javalin
I am a Teapot
With a body!
Run 2
$ http http://localhost:5454/test-future
HTTP/1.1 418 I'm a Teapot
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Date: Thu, 09 Nov 2017 10:59:10 GMT
Server: Javalin
No more body 😦
/test-future-long
$ http http://localhost:5454/test-future-long
HTTP/1.1 418 I'm a Teapot
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Date: Thu, 09 Nov 2017 10:59:49 GMT
Server: Javalin
Body is empty.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Not getting returned value from async await function
You have to returned the response from axios, which is what will be returned by the wrapping function. just add return in front...
Read more >async function - JavaScript - MDN Web Docs - Mozilla
An async function will return a different reference, whereas Promise.resolve returns the same reference if the given value is a promise. It can...
Read more >Use Promise.all to Stop Async/Await from Blocking Execution ...
When writing asynchronous code, async/await is a powerful tool — but it comes with risks! ... Promises don't return values for use outside...
Read more >Asynchronous programming: futures, async, await - Dart
This codelab teaches you how to write asynchronous code using futures and the async and await keywords. Using embedded DartPad editors, you can...
Read more >Task asynchronous programming model - Microsoft Learn
A synchronous method returns when its work is complete (step 5), but an async method returns a task value when its work is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll just close this, as it can’t really be fixed in an acceptable way. I have deprecated the method.
@Adeynack, what do you think about removing this way of doing async in favor of
ctx.result(future)
?