注册锁

This commit is contained in:
chaosBreaking
2019-10-02 13:35:25 +08:00
parent 9cf8795fa4
commit 298d3da92d
2 changed files with 76 additions and 97 deletions

21
src/utils/mutexlock.js Normal file
View 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;