mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-03 19:34:24 +00:00
refactor(lock): centralize lock utility functions
- Moved `withTimeout` to `src/utils.mjs` and exported it. - Updated `src/lock-utils.mjs` to re-export `withTimeout` and `mergeRelayList` from `src/utils.mjs`. - Removed duplicate local definitions of `withTimeout` and `mergeRelayList` in `src/lock-ops.mjs` and `src/lock-publisher.mjs`. - Fixed `test/utils.test.mjs` to import `mergeRelayList`. - Verified all tests pass with `npm test`. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
8d43fc1be8
commit
08d291e7fa
5 files changed
+14
-37
No files matched your search
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user