【发布时间】:2017-05-28 03:09:39
【问题描述】:
我有一个运行大约 40 个 oracle 连接/查询的 nodejs 应用程序。我正在使用 async 来限制来自proposed solution here 的异步调用。我的问题是在我的函数/查询完成之前排水回调正在运行和完成。非常感谢任何帮助。
var queue = async.queue(runAsyncCallout, 5);
queue.concurrency = 5;
db.collection('callout').find({'active':0}).each(function(error, callout) {
queue.push(callout);
});
queue.drain = function() {
db.collection('callout_lock').update({'context': 'ALL_CALLOUTS'}, {$set: {'lock': '0'}});
db.collection('callout_lock').update({'context': 'ALL_CALLOUTS'}, {$set: {'date': time_stamp}});
console.log("All callouts done unlocking");
};
queue.concurrency = 5;
function runAsyncCallout(callout, callback) {
switch(callout.db_connect){//Grab connection profiles
case "A":
connAttrs=A;
break;
case "B":
connAttrs=B;
break;
case "C":
connAttrs=C;
break;
default:
connAttrs=D;
}
oracledb.getConnection(connAttrs, function (e, connection) {
connection.execute(callout.query, {}, {
outFormat: oracledb.OBJECT
}, function (e, result) {
//Sparing the details here, run oracle query and save to mongodb
doRelease(connection);
});
});
callback();
}
【问题讨论】:
-
欢迎来到 StackOverflow。是否有可能调用
oracledb.getConnection是异步完成的?如果是这样,runAsyncCallout会触发,调用oracledb.getConnection,然后它会去做它的事情,但与此同时runAsyncCallout会继续并可能在实际查询执行之前返回给调用者。
标签: node.js asynchronous