Skip to content

Commit 8af9dfb

Browse files
committed
Client is not guaranteed to exist
1 parent 05db462 commit 8af9dfb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/interfaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,6 @@ export type WorkerEventMap = {
908908
"pool:listen:error": {
909909
workerPool: WorkerPool;
910910
error: unknown;
911-
client: PoolClient;
912911
};
913912

914913
/**

src/main.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export function runTaskListInternal(
363363

364364
const listenForChanges = (
365365
err: Error | undefined,
366-
client: PoolClient,
366+
maybeClient: PoolClient | undefined,
367367
releaseClient: () => void,
368368
) => {
369369
if (!workerPool._active) {
@@ -373,7 +373,7 @@ export function runTaskListInternal(
373373
}
374374

375375
const reconnectWithExponentialBackoff = (err: Error) => {
376-
events.emit("pool:listen:error", { workerPool, client, error: err });
376+
events.emit("pool:listen:error", { workerPool, error: err });
377377

378378
attempts++;
379379

@@ -400,11 +400,17 @@ export function runTaskListInternal(
400400
}, delay);
401401
};
402402

403-
if (err) {
403+
if (err || !maybeClient) {
404404
// Try again
405-
reconnectWithExponentialBackoff(err);
405+
reconnectWithExponentialBackoff(
406+
err ??
407+
new Error(
408+
`This should never happen, this error only exists to satisfy TypeScript`,
409+
),
410+
);
406411
return;
407412
}
413+
const client = maybeClient;
408414

409415
//----------------------------------------
410416

0 commit comments

Comments
 (0)