Skip to content

Commit

Permalink
Add possibility to unlock all
Browse files Browse the repository at this point in the history
  • Loading branch information
XeniaSiskaki committed Apr 28, 2018
1 parent a40c25b commit 6bf8f9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ if (mutex.tryLock()) {
}
```

Release all locks:
```javascript
mutex.unlockAll();
```

### Read/Write locks

Read/Write Locks are used to allow many actors to read from a resource, as
Expand Down
4 changes: 4 additions & 0 deletions lib/Mutex.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ Mutex.prototype.unlock = function () {
this._isLocked = false;
}
};

Mutex.prototype.unlockAll = function() {
this._waiting = [];
};
10 changes: 10 additions & 0 deletions test/mutex.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ test('Mutex', function (t) {
});
});
});

mutex.lock(function () {
t.equal(mutex.isLocked, true, 'Locked');
});

mutex.lock(function () {
t.equal(mutex.isLocked, true, 'Locked');
mutex.unlockAll();
t.equal(mutex.isLocked, false, 'Lock is waiting to be acquired');
});
});

0 comments on commit 6bf8f9a

Please sign in to comment.