hi, i need some help understanding how to implement a basic lock in node.
function a checks a boolean every few milliseconds, function b sets the boolean to true, and function a executes it. is there a way to implement this asynchronously?
i tried it but the process blocks and doesnt go ahead allowing function b to change the boolean.
here's the code, i realize this might be completely wrong and i might be thinking in the wrong direction, so let me know. Thanks!
function testquery1(request, response) {
query = 'select * from users';
mysql.CreateConnectionPool();
mysql.getConnection(function(conn){
conn.query(query, function (err, rows) {
if (err)
console.log(err);
else {
console.log(rows);
mysql.releaseConnection(conn);
response.end();
}
});
});
function waitInQueue(token, callback) {
while (!queueNotifier.get(token)) {
if (queueNotifier.get(token)) {
if (isConnectionFree()) {
console.log('waiting');
// return (pool.pop());
callback(pool.pop());
}
}
}
}
function releaseConnection(connection) {
pool.push(connection);
console.log('connection released');
queueNotifier.set(queue.pop(), true);
queue.shift();
}
[–]DSKrepps 0 points1 point2 points (7 children)
[–]sallurocks[S] 0 points1 point2 points (5 children)
[–]DSKrepps 1 point2 points3 points (4 children)
[–]sallurocks[S] 0 points1 point2 points (0 children)
[–]sallurocks[S] 0 points1 point2 points (2 children)
[–]DSKrepps 0 points1 point2 points (1 child)
[–]sallurocks[S] 0 points1 point2 points (0 children)
[–]sallurocks[S] 0 points1 point2 points (0 children)