@xuda.io/account_module 1.2.2024 → 1.2.2026
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/index_ms.mjs +26 -3
- package/package.json +1 -1
package/index_ms.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// =====================================================
|
|
5
5
|
|
|
6
6
|
import amqplib from 'amqplib';
|
|
7
|
+
import { randomUUID } from 'crypto';
|
|
7
8
|
|
|
8
9
|
let queue={}
|
|
9
10
|
|
|
@@ -36,8 +37,30 @@ let queue={}
|
|
|
36
37
|
|
|
37
38
|
const send_to_queue =async function(ms_method, ...args) {
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
const queue_id = randomUUID();
|
|
41
|
+
return new Promise((resolve,reject)=>{
|
|
42
|
+
|
|
43
|
+
queue[queue_id] = { resolve, reject };
|
|
44
|
+
|
|
45
|
+
// Set timeout to prevent hanging
|
|
46
|
+
const timeout = setTimeout(() => {
|
|
47
|
+
delete queue[queue_id];
|
|
48
|
+
reject(new Error(`Queue timeout for ${ms_method}`));
|
|
49
|
+
}, 30000); // 30 second timeout
|
|
50
|
+
|
|
51
|
+
// Wrap resolve to clean up
|
|
52
|
+
queue[queue_id].resolve = (value) => {
|
|
53
|
+
clearTimeout(timeout);
|
|
54
|
+
delete queue[queue_id];
|
|
55
|
+
resolve(value);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Wrap reject to clean up
|
|
59
|
+
queue[queue_id].reject = (error) => {
|
|
60
|
+
clearTimeout(timeout);
|
|
61
|
+
delete queue[queue_id];
|
|
62
|
+
reject(error);
|
|
63
|
+
};
|
|
41
64
|
|
|
42
65
|
global[`_${global.module_in}_ch`].sendToQueue(
|
|
43
66
|
'account_module',
|
|
@@ -52,7 +75,7 @@ const send_to_queue =async function(ms_method, ...args) {
|
|
|
52
75
|
);
|
|
53
76
|
|
|
54
77
|
})
|
|
55
|
-
|
|
78
|
+
|
|
56
79
|
};
|
|
57
80
|
|
|
58
81
|
// You must define this somewhere before using these wrappers:
|