On Aug 12, 2014, at 10:55 PM, Pradeep Simha <[email protected]> wrote:
> My situation is like this, I have a server like this and inside I am calling 
> another callback function which gets multiple values:
>     
>     var http = require('http'); 
>     var server = http.createServer(req,resp) {
>          var finalVal = "";
>          
>          consumer.on('message',function(message) {
>              finalVal = message;
>              console.log(finalVal);
>          });
> 
>          resp.end(finalVal);
>     });
> 

Well, you can move the resp.end() inside the function(message) { } block. But 
if consumer.on() can fire multiple times and you need to accumulate the 
messages, how do you know when the data is complete? You will need to add a 
check for that.

        --ravi



> My finalVal should display all the multiple values it fetches and send it as 
> a response, but problem is it's sending only first value where as console.log 
> displays all the values. I do understand that by the time consumer.on ends 
> response would have committed. Can someone please help me how to handle this 
> scenario since I'm very new to Node.js ? Currently due to heavy deadlines I 
> don't have time to read full information about callbacks. But defnitely I 
> would take time to learn about callbacks.
> 
> Here `consumer.on` calls multiple times till it fetches all the data from 
> backend, I need to send all those data in a final response. I am using 
> `node-kafka` to consume to kafka messages.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/0AEDAF58-E503-4A12-8BED-5D957025017F%40g8o.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to