-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a mutex lock on the groups object in a hope it fixed random del…
…etion of all group data. (#141)
- Loading branch information
1 parent
70f8773
commit ef2bd2a
Showing
2 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
'use strict'; | ||
|
||
class Mutex { | ||
constructor() { | ||
this._locking = Promise.resolve(); | ||
this._locked = false; | ||
} | ||
|
||
isLocked() { | ||
return this._locked; | ||
} | ||
|
||
lock() { | ||
this._locked = true; | ||
|
||
let unlockNext; | ||
let willLock = new Promise(resolve => unlockNext = resolve); | ||
|
||
willLock.then(() => this._locked = false); | ||
|
||
let willUnlock = this._locking.then(() => unlockNext); | ||
this._locking = this._locking.then(() => willLock); | ||
|
||
return willUnlock; | ||
} | ||
} | ||
|
||
export default Mutex; |