注册锁
This commit is contained in:
21
src/utils/mutexlock.js
Normal file
21
src/utils/mutexlock.js
Normal file
@@ -0,0 +1,21 @@
|
||||
class MLock {
|
||||
constructor (props) {
|
||||
Object.defineProperty(this, 'map', {
|
||||
value: new Map(),
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
acquire (key) {
|
||||
if (this.map.has(key)) {
|
||||
return false;
|
||||
}
|
||||
this.map.set(key, true);
|
||||
return true;
|
||||
}
|
||||
unlock (key) {
|
||||
this.map.delete(key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MLock;
|
||||
Reference in New Issue
Block a user