This commit is contained in:
aozhiwei 2024-06-03 14:24:10 +08:00
parent e3b86e927f
commit db832e2669

21
app.js
View File

@ -11,6 +11,7 @@ const app = express();
const handlers = {};
const middlewares = {};
const dbPools = {};
const lockHash = {};
let sessionClass = null;
let useMiddlewares = [];
@ -204,6 +205,24 @@ registerHandler('Ops', 'selfChecking', async (req, rsp) => {
}
});
async function lock(key) {
if (key in lockHash) {
lockHash[key] += 1;
} else {
lockHash[key] = 1;
}
const oldTimes = lockHash[key];
while (lockHash[key] == oldTimes) {
await sleep(0.05);
}
}
function unLock(key) {
if (key in lockHash) {
lockHash[key] -= 1;
}
}
exports.init = init;
exports.listen = listen;
exports.get = get;
@ -219,3 +238,5 @@ exports.getPid = getPid;
exports.getNodeId = getNodeId;
exports.getInstanceId = getInstanceId;
exports.sleep = sleep;
exports.lock = lock;
exports.unLock = unLock;