【发布时间】:2014-03-08 02:16:31
【问题描述】:
嘿嘿, 我在 Windows Azure Mobile 服务中创建 API,在这个 api 脚本中我有连接其他服务的功能。当我从服务中得到很好的答案时,我遇到了如何返回值或停止可执行我的脚本的问题。函数process.exit(1),不起作用。
function function1(item,response) {
var buf ='';
var net = require('net');
var HOST = 'xxxx.xxxx.xxxx.xxxx';
var PORT = xxx;
var client = new net.Socket();
client.setTimeout(100000, function() {
console.log("Timeout");
response.send(500, "Timeout");
});
client.connect(PORT, HOST, function() {
client.write(item + "\n");
client.on('data', function(data) {
buf = buf + data.toString('utf-8');
});
client.on('close', function() {
});
client.on('end', function() {
if (buf.length > 1) {
var result = JSON.parse(buf);
//if resulr.Aviable is true the functios should return result or send result and stop execiuting script
if ( result.Avaiable) {
response.send(200, result);
//now i wont't to respond answer to client or return my value(result)
console.log('Send data');
}
}
client.destroy();
});
});
}
【问题讨论】:
-
你的代码中有 response.send ,那不是返回你的结果吗?您期望发生的事情没有发生?
-
但如果我将
response.send更改为return result。函数返回未定义的参数。
标签: node.js azure azure-mobile-services