koishi-plugin-bilibili-notify 3.2.1-alpha.0 → 3.2.1-alpha.1

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.
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 高阶函数:为函数添加锁机制
5
- * @param {Function} fn - 需要包装的原始函数
6
- * @returns {Function} 带锁功能的函数
7
- */
8
- function withLock(fn) {
9
- // 判断是否是异步函数
10
- const isAsync = fn.constructor.name === 'AsyncFunction';
11
- // 定义锁标志
12
- let locked = false;
13
- // 判断是否为异步函数
14
- if (isAsync) {
15
- // 变为Promise
16
- return function (...args) {
17
- // 已加锁则跳过执行
18
- if (locked)
19
- return;
20
- // 获取锁
21
- locked = true;
22
- // 将异步函数转为Promise链
23
- Promise.resolve(fn(...args))
24
- .catch(err => {
25
- // 打印错误
26
- console.error("Execution error:", err);
27
- // 重新抛出错误
28
- throw err;
29
- })
30
- .finally(() => {
31
- // 确保释放锁
32
- locked = false;
33
- });
34
- };
35
- }
36
- // 不是异步函数
37
- return function (...args) {
38
- // 已加锁则跳过执行
39
- if (locked)
40
- return;
41
- // 获取锁
42
- locked = true;
43
- try {
44
- // 执行函数
45
- fn(...args);
46
- }
47
- catch (err) {
48
- // 打印错误
49
- console.error("Execution error:", err);
50
- // 重新抛出错误
51
- throw err;
52
- }
53
- finally {
54
- // 无论成功失败都释放锁
55
- locked = false;
56
- }
57
- };
58
- }
59
- exports.default = withLock;