superlock 1.0.7 → 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 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 delay(Math.random() * 100)
38
+ await setTimeout(Math.random() * 100)
39
39
  return index
40
40
  })
41
41
  )
@@ -57,7 +57,7 @@ It returns a function that can be used to wrap any code you want to execute with
57
57
  ```js
58
58
  const { withLock } = require('superlock')
59
59
 
60
- const lock = createLock()
60
+ const lock = withLock()
61
61
 
62
62
  await lock(() => {
63
63
  /* your code execution */
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.7",
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 };