1
This commit is contained in:
parent
e3b86e927f
commit
db832e2669
21
app.js
21
app.js
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user