superlock 1.0.8 → 1.1.0
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/README.md +2 -2
- package/package.json +2 -1
- package/src/index.d.ts +19 -0
package/README.md
CHANGED
|
@@ -27,15 +27,15 @@ $ npm install superlock --save
|
|
|
27
27
|
The lock is a mutex by default:
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
|
+
const { setTimeout } = require('timers/promises')
|
|
30
31
|
const { withLock } = require('superlock')
|
|
31
|
-
const delay = require('delay')
|
|
32
32
|
|
|
33
33
|
const lock = withLock()
|
|
34
34
|
|
|
35
35
|
const executions = await Promise.all(
|
|
36
36
|
[...Array(10).keys()].map(index =>
|
|
37
37
|
lock(async () => {
|
|
38
|
-
await
|
|
38
|
+
await setTimeout(Math.random() * 100)
|
|
39
39
|
return index
|
|
40
40
|
})
|
|
41
41
|
)
|
package/package.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"name": "superlock",
|
|
3
3
|
"description": "The most simple mutex/semaphore implementation",
|
|
4
4
|
"homepage": "https://github.com/Kikobeats/superlock",
|
|
5
|
-
"version": "1.0
|
|
5
|
+
"version": "1.1.0",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
6
7
|
"main": "src/index.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./src/index.js",
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare type Release = () => void;
|
|
2
|
+
declare type Acquire = (resolve: (release: Release) => void) => void;
|
|
3
|
+
declare type Lock = () => Promise<Release>;
|
|
4
|
+
|
|
5
|
+
interface LockInterface extends Lock {
|
|
6
|
+
isLocked: () => boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare function createLock(slots?: number): LockInterface;
|
|
10
|
+
|
|
11
|
+
declare type WithLock = <T>(fn: () => Promise<T>) => Promise<T>;
|
|
12
|
+
|
|
13
|
+
interface WithLockInterface extends WithLock {
|
|
14
|
+
isLocked: () => boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function withLock(opts: number): WithLockInterface;
|
|
18
|
+
|
|
19
|
+
export { withLock, createLock };
|