[mirotalksfu] - add upload to s3 recording
هذا الالتزام موجود في:
29
app/src/MutexManager.js
Normal file
29
app/src/MutexManager.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const { Mutex } = require('async-mutex');
|
||||
|
||||
// In-memory file mutex registry
|
||||
const fileLocks = new Map();
|
||||
|
||||
function getFileMutex(filePath) {
|
||||
if (!fileLocks.has(filePath)) {
|
||||
fileLocks.set(filePath, new Mutex());
|
||||
}
|
||||
return fileLocks.get(filePath);
|
||||
}
|
||||
|
||||
async function withFileLock(filePath, fn) {
|
||||
const mutex = getFileMutex(filePath);
|
||||
const release = await mutex.acquire();
|
||||
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
release();
|
||||
if (!mutex.isLocked()) {
|
||||
fileLocks.delete(filePath); // Clean up when no one is waiting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { withFileLock };
|
||||
المرجع في مشكلة جديدة
حظر مستخدم