@whitesev/utils 1.1.1 → 1.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
@@ -21,6 +21,7 @@ class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
21
21
  */
22
22
  constructor(callback: K, context?: any, delayTime?: number);
23
23
  constructor(callback: K, context?: any, delayTime?: number) {
24
+ let that = this;
24
25
  this.#callback = callback;
25
26
  if (typeof context === "number") {
26
27
  this.#delayTime = context;
@@ -29,37 +30,36 @@ class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
29
30
  this.#delayTime = delayTime as number;
30
31
  this.#context = context;
31
32
  }
32
-
33
33
  /**
34
34
  * 锁
35
35
  */
36
36
  this.lock = function () {
37
- this.#flag = true;
37
+ that.#flag = true;
38
38
  };
39
39
  /**
40
40
  * 解锁
41
41
  */
42
42
  this.unlock = function () {
43
43
  setTimeout(() => {
44
- this.#flag = false;
45
- }, this.#delayTime);
44
+ that.#flag = false;
45
+ }, that.#delayTime);
46
46
  };
47
47
  /**
48
48
  * 判断是否被锁
49
49
  */
50
50
  this.isLock = function () {
51
- return this.#flag;
51
+ return that.#flag;
52
52
  };
53
53
  /**
54
54
  * 执行
55
55
  */
56
56
  this.run = async function (...args: any[]) {
57
- if (this.isLock()) {
57
+ if (that.isLock()) {
58
58
  return;
59
59
  }
60
- this.lock();
61
- await this.#callback.apply(this.#context, args);
62
- this.unlock();
60
+ that.lock();
61
+ await that.#callback.apply(that.#context, args);
62
+ that.unlock();
63
63
  };
64
64
  }
65
65
  }