mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 07:51:52 +00:00
Merge branch 'main' into fix/governance-command-injection-10151244085139343159
This commit is contained in:
4 files changed
+14
-2
No files matched your search
@@ -6,6 +6,8 @@ import {
|
||||
getRelayFallbacks,
|
||||
getMinActiveRelayPool,
|
||||
} from './torch-config.mjs';
|
||||
import { mergeRelayList, relayListLabel, withTimeout } from './utils.mjs';
|
||||
import { secureRandom } from './lock-utils.mjs';
|
||||
import { defaultHealthManager, buildRelayHealthConfig } from './relay-health-manager.mjs';
|
||||
import { relayListLabel } from './utils.mjs';
|
||||
import { mergeRelayList, withTimeout } from './lock-utils.mjs';
|
||||
|
||||
@@ -4,7 +4,7 @@ import WebSocket from 'ws';
|
||||
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools/pure';
|
||||
import { getNamespace, getRelays } from './torch-config.mjs';
|
||||
import { MS_PER_SECOND } from './constants.mjs';
|
||||
import { withTimeout } from './lock-utils.mjs';
|
||||
import { withTimeout } from './utils.mjs';
|
||||
|
||||
const PROBE_KIND = 27235;
|
||||
|
||||
|
||||
@@ -55,3 +55,13 @@ export function ensureDir(dir) {
|
||||
export function relayListLabel(relays) {
|
||||
return relays.join(', ');
|
||||
}
|
||||
|
||||
export function withTimeout(promise, timeoutMs, timeoutMessage) {
|
||||
let timeoutHandle;
|
||||
const timeoutPromise = new Promise((_, reject) => {
|
||||
timeoutHandle = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
|
||||
});
|
||||
return Promise.race([promise, timeoutPromise]).finally(() => {
|
||||
if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import { withTimeout } from '../src/lock-utils.mjs';
|
||||
import { withTimeout } from '../src/utils.mjs';
|
||||
|
||||
describe('Async Utilities', () => {
|
||||
describe('withTimeout', () => {
|
||||
|
||||
Reference in new issue
Block a user