Good morning stackoverflow
I have this route:
app.get('/myaccount', messages.getMessages, function(req, res, next) {
messages = '';
res.render('myaccount', {
messages: messages
});
});
the messages.getMessages does a bunch of stuff by calling out to another server via superagent and getting some messages to bring back to the user (in that messages variable)
The problem here is that sometimes... messages.getMessages might take 2-3 seconds to retrieve all the messages so when I refresh the page sometimes I see the messages... sometimes I don't its very random.
I am rather new to node but I assume that messages.getMessages is async so that the page might be fully rendered and all variables passed to jadejs before I get my messages back.
How can I basically require the route to wait until I get messages.getMessages data before proceeding to render the route?
Thanks!