@konemono/nostr-login 1.7.15 → 1.7.16
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
|
@@ -24,8 +24,18 @@ class ProcessManager extends EventEmitter {
|
|
|
24
24
|
public async wait<T>(cb: () => Promise<T>): Promise<T> {
|
|
25
25
|
// FIXME only allow 1 parallel req
|
|
26
26
|
|
|
27
|
+
let timeoutReject: ((reason?: any) => void) | undefined;
|
|
28
|
+
const timeoutPromise = new Promise<T>((_, reject) => {
|
|
29
|
+
timeoutReject = reject;
|
|
30
|
+
});
|
|
31
|
+
|
|
27
32
|
if (!this.callTimer) {
|
|
28
|
-
this.callTimer = setTimeout(() =>
|
|
33
|
+
this.callTimer = setTimeout(() => {
|
|
34
|
+
this.emit('onCallTimeout');
|
|
35
|
+
if (timeoutReject) {
|
|
36
|
+
timeoutReject(new Error('Request timed out'));
|
|
37
|
+
}
|
|
38
|
+
}, CALL_TIMEOUT);
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
if (!this.callCount) {
|
|
@@ -38,7 +48,7 @@ class ProcessManager extends EventEmitter {
|
|
|
38
48
|
let result;
|
|
39
49
|
|
|
40
50
|
try {
|
|
41
|
-
result = await cb();
|
|
51
|
+
result = await Promise.race([cb(), timeoutPromise]);
|
|
42
52
|
} catch (e) {
|
|
43
53
|
error = e;
|
|
44
54
|
}
|