Address review feedback for waitForReady and helpers
Change lastError type to unknown to match catch clause semantics, and disconnect failed Keyv instances in attemptKeyvConnection to avoid leaking sockets/handles during readiness polling. Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Made-with: Cursor
This commit is contained in:
+16
-4
@@ -31,10 +31,22 @@ export async function attemptKeyvConnection(
|
||||
|
||||
await waitForReady(async () => {
|
||||
const store = createStore(connection);
|
||||
keyv = new Keyv({ store });
|
||||
const value = uuid();
|
||||
await keyv.set('test', value);
|
||||
return (await keyv.get('test')) === value;
|
||||
const attemptKeyv = new Keyv({ store });
|
||||
let succeeded = false;
|
||||
|
||||
try {
|
||||
const value = uuid();
|
||||
await attemptKeyv.set('test', value);
|
||||
succeeded = (await attemptKeyv.get('test')) === value;
|
||||
if (succeeded) {
|
||||
keyv = attemptKeyv;
|
||||
}
|
||||
return succeeded;
|
||||
} finally {
|
||||
if (!succeeded) {
|
||||
await attemptKeyv.disconnect();
|
||||
}
|
||||
}
|
||||
}, label);
|
||||
|
||||
return keyv!;
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function waitForReady(
|
||||
): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
|
||||
let lastError: Error | undefined;
|
||||
let lastError: unknown;
|
||||
let attempts = 0;
|
||||
for (;;) {
|
||||
attempts += 1;
|
||||
|
||||
Reference in New Issue
Block a user