1 | ;
|
2 |
|
3 | module.exports = function () {
|
4 |
|
5 | var locks = {};
|
6 |
|
7 | var locker = {
|
8 | /**
|
9 | * Add a lock for a resource identified by the given key
|
10 | * @param {String} key
|
11 | */
|
12 | addLock: function (key) {
|
13 | locks[key] = true;
|
14 | },
|
15 |
|
16 | /**
|
17 | * Remove a lock on a resource identified by the given key
|
18 | * @param {String} key
|
19 | */
|
20 | removeLock: function (key) {
|
21 | delete locks[key];
|
22 | },
|
23 |
|
24 | /**
|
25 | * Returns a boolean inidicating if the reosurce identified by key is
|
26 | * currently locked
|
27 | * @param {String} key
|
28 | * @return {Boolean}
|
29 | */
|
30 | isLocked: function (key) {
|
31 | return (locks[key]) ? true : false;
|
32 | }
|
33 | };
|
34 |
|
35 | return locker;
|
36 | };
|