Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
fix: check if connected
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Feb 21, 2024
1 parent 10dcbb1 commit adbef38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ProcessBootstrapper {
shardId
} satisfies WorkerReceivePayload;
try {
process.send!(payload);
if (process.connected) process.send!(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => process.send!(payload)), 2_000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export class ProcessContextFetchingStrategy implements IContextFetchingStrategy
const promise = new Promise<SessionInfo | null>(resolve => this.sessionPromises.set(nonce, resolve));

try {
process.send!(payload);
if (process.connected && process.connected) process.send!(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => process.send!(payload)), 2_000);
setTimeout(async () => Result.fromAsync(() => { if (process.connected) process.send!(payload); }), 2_000);
}
return promise;
}
Expand All @@ -61,9 +61,9 @@ export class ProcessContextFetchingStrategy implements IContextFetchingStrategy
session: sessionInfo
} satisfies WorkerReceivePayload;
try {
process.send!(payload);
if (process.connected) process.send!(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => process.send!(payload)), 2_000);
setTimeout(async () => Result.fromAsync(() => { if (process.connected) process.send!(payload); }), 2_000);
}
}

Expand All @@ -79,9 +79,9 @@ export class ProcessContextFetchingStrategy implements IContextFetchingStrategy
const promise = new Promise<void>((resolve, reject) => this.waitForIdentifyPromises.set(nonce, { resolve, reject }));

try {
process.send!(payload);
if (process.connected) process.send!(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => process.send!(payload)), 2_000);
setTimeout(async () => Result.fromAsync(() => { if (process.connected) process.send!(payload); }), 2_000);
}

const listener = (): void => {
Expand All @@ -90,9 +90,9 @@ export class ProcessContextFetchingStrategy implements IContextFetchingStrategy
nonce
};
try {
process.send!(message);
if (process.connected) process.send!(message);
} catch {
setTimeout(async () => Result.fromAsync(() => process.send!(message)), 2_000);
setTimeout(async () => Result.fromAsync(() => { if (process.connected) process.send!(message); }), 2_000);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class ProcessShardingStrategy implements IShardingStrategy {

const promise = new Promise<void>(resolve => this.connectPromises.set(shardId, resolve));
try {
worker.send(payload);
if (worker.connected) worker.send(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => worker.send(payload)), 2_000);
}
Expand All @@ -106,7 +106,7 @@ export class ProcessShardingStrategy implements IShardingStrategy {

const promise = new Promise<void>(resolve => this.destroyPromises.set(shardId, resolve)).then(() => worker.kill());
try {
worker.send(payload);
if (worker.connected) worker.send(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => worker.send(payload)), 2_000);
}
Expand All @@ -132,7 +132,7 @@ export class ProcessShardingStrategy implements IShardingStrategy {
payload: data
} satisfies WorkerSendPayload;
try {
worker.send(payload);
if (worker.connected) worker.send(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => worker.send(payload)), 2_000);
}
Expand All @@ -154,7 +154,7 @@ export class ProcessShardingStrategy implements IShardingStrategy {

const promise = new Promise<WebSocketShardStatus>(resolve => this.fetchStatusPromises.set(nonce, resolve));
try {
worker.send(payload);
if (worker.connected) worker.send(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => worker.send(payload)), 2_000);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ export class ProcessShardingStrategy implements IShardingStrategy {
shardId
} satisfies WorkerSendPayload;
try {
worker.send(payload);
if (worker.connected) worker.send(payload);
} catch {
setTimeout(async () => Result.fromAsync(() => worker.send(payload)), 2_000);
}
Expand Down

0 comments on commit adbef38

Please sign in to comment.