question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async does not return the result body

See original GitHub issue

The “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).

https://github.com/Adeynack/javalin/blob/async-does-not-response-with-body/src/test/kotlin/io/javalin/examples/AsyncExample.kt

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:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Feb 2, 2018

I’ll just close this, as it can’t really be fixed in an acceptable way. I have deprecated the method.

1reaction
tipsycommented, Dec 30, 2017

@Adeynack, what do you think about removing this way of doing async in favor of ctx.result(future)?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found