@tb-dev/vue 2.1.0 → 2.2.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.
@@ -2,4 +2,5 @@ export declare function useMutex(): {
2
2
  locked: Readonly<import('vue').Ref<boolean, boolean>>;
3
3
  acquire: () => Promise<void>;
4
4
  release: () => void;
5
+ lock: <T = unknown>(fn: () => Promise<T>) => Promise<T>;
5
6
  };
package/dist/index.js CHANGED
@@ -22,10 +22,16 @@ function useMutex() {
22
22
  mutex.release();
23
23
  locked.value = mutex.isLocked;
24
24
  }
25
+ function lock(fn) {
26
+ const { resolve, reject, promise } = Promise.withResolvers();
27
+ acquire().then(() => fn()).then((value) => resolve(value)).catch(reject).finally(release);
28
+ return promise;
29
+ }
25
30
  return {
26
31
  locked: readonly(locked),
27
32
  acquire,
28
- release
33
+ release,
34
+ lock
29
35
  };
30
36
  }
31
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/vue",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Vue utilities",
5
5
  "license": "MIT",
6
6
  "type": "module",