I've a return type function:
var responseData = '';
function getResponseFromKey(key){
client.get(key, function(err, reply){
responseData = reply;
});
return responseData;
}
When I call this function first time it returns blank and then second time returns my value what I want after running again.
I'm calling this function to print in html page.
http.createServer(function(request, response){
response.writeHead(200, {'Content-Type':'text/plain'});
getResponseFromKey("my_key");
console.log(responseData);
}).listen(8083);
As I'm familiar with node the function is going in asynchronous way. Can you please help me to make synchronous way? Do I need to use generators
in that case?
Help would be appreciated!