superlock 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -2
- package/src/create.js +12 -4
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "superlock",
|
|
3
3
|
"description": "The minimal Node.js concurrency toolkit: mutex, semaphore and fair queue for async/await, with no dependencies.",
|
|
4
4
|
"homepage": "https://superlock.js.org/",
|
|
5
|
-
"version": "1.4.
|
|
5
|
+
"version": "1.4.7",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"exports": {
|
|
@@ -90,9 +90,15 @@
|
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
92
|
"c8": {
|
|
93
|
+
"all": true,
|
|
94
|
+
"branches": 100,
|
|
95
|
+
"check-coverage": true,
|
|
96
|
+
"functions": 100,
|
|
93
97
|
"include": [
|
|
94
98
|
"src/**/*.js"
|
|
95
|
-
]
|
|
99
|
+
],
|
|
100
|
+
"lines": 100,
|
|
101
|
+
"statements": 100
|
|
96
102
|
},
|
|
97
103
|
"commitlint": {
|
|
98
104
|
"extends": [
|
package/src/create.js
CHANGED
|
@@ -11,18 +11,25 @@ module.exports = (slots = 1) => {
|
|
|
11
11
|
if (waiter) return waiter.acquire()
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const ready = Promise.resolve(release)
|
|
15
|
+
|
|
14
16
|
const acquire = resolve => {
|
|
15
17
|
--slots
|
|
16
18
|
resolve(release)
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
const lock = signal =>
|
|
20
|
-
|
|
21
|
+
const lock = signal => {
|
|
22
|
+
if (signal == null && slots !== 0) {
|
|
23
|
+
--slots
|
|
24
|
+
return ready
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return new Promise(resolve => {
|
|
21
28
|
if (signal != null && typeof signal.addEventListener !== 'function') {
|
|
22
29
|
throw new TypeError('`signal` needs to be an AbortSignal.')
|
|
23
30
|
}
|
|
24
|
-
if (signal
|
|
25
|
-
if (
|
|
31
|
+
if (signal != null && signal.aborted) return resolve(null)
|
|
32
|
+
if (slots !== 0) return acquire(resolve)
|
|
26
33
|
|
|
27
34
|
const waiter = { acquire: () => acquire(resolve) }
|
|
28
35
|
const node = queue.enqueue(waiter)
|
|
@@ -39,6 +46,7 @@ module.exports = (slots = 1) => {
|
|
|
39
46
|
signal.addEventListener('abort', onAbort, { once: true })
|
|
40
47
|
}
|
|
41
48
|
})
|
|
49
|
+
}
|
|
42
50
|
|
|
43
51
|
lock.isLocked = () => slots === 0
|
|
44
52
|
|