我试图将一个值从js函数调用中返回为
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
var r="";
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well ping');
function getmeresResult(err, result) {
if (err) return err;
console.log("Got res in ping "+result);
return result;
}
r=getmeres(client,getmeresResult);
console.log("inner r is "+r);
return r;
}
});
console.log("outer r is "+r);
这给了我
Got res in ping 12,12,23
inner r is 12,12,23
console.log("outer r is "+r);
永远不会打印出来!这是为什么?我怎样才能得到结果' out' client.ping函数调用?