Helo, 我在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,是不是返回你的結果?什麼沒有發生,你期望發生? – MikeWo
但如果我將'response.send'更改爲'return result'。函數返回未定義的參數。 – user3125146