据我所知,这是一个stream
所以它不断地将值传输到Oracle数据库。
我想知道我是否可以执行超时功能等待大约3秒再发送一次。
var net = require('net');
var fs = require('fs');
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');
var client = new net.Socket();
client.connect(8080, "192.168.0.7");
console.log("Client most likely connected...");
oracledb.getConnection(
{
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString
},
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
client.on('data', function (data) {
var weight_data = Number(data);
console.log('Data: ' + data);
connection.execute("INSERT INTO UNI_SCRAP_SCALE(WEIGHT) VALUES (:weight)", [weight_data], function (err, result) {
if (err) throw err;
console.log("Rows inserted: " + result.rowsAffected);
console.log('Data received from Db:\n');
console.log(result);
connection.commit(
function (err) {
console.log('Done')
});
});
});
});
});
// client.destroy();
答案 0 :(得分:1)
在JavaScript中有一个设置超时的函数,setTimeout(),这是一个例子:
setTimeout(function {
// place your code here
}, 3000); //number of millisecond before executing code
您的代码将在3秒后执行。
答案 1 :(得分:0)
JavaScript的:
setTimeout(function () {
// code you want to wait for here
}, 3000);