Can I send asynchronous response with Kitura

149 views Asked by At

Is it possible to send a response to the client and do some work on other thread, then send another response to the client, the that work is done?

Current state: until I call next() block in my async callback method, user doesn't get any data. Expected: get first response, then append the second response to the first response. Is it possible? Or it doesn't even make sense?

2

There are 2 answers

0
Youming Lin On BEST ANSWER

I don't think the HTTP standard allows for server to respond multiple times per request. Several Stack Overflow answers mention this:

https://stackoverflow.com/a/2966735

https://stackoverflow.com/a/31224172

https://stackoverflow.com/a/29529139

Your use case sounds more like client-server messaging; I suggest looking into Kitura-Websocket and see if that can solve your issue.

0
Navneet On

Kitura RouterResponse buffers the response till end() is called. So there is not currently a way to do what you want. That may change in future releases of Kitura.