Skip to content

Commit

Permalink
Throw on disconnect
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Jan 23, 2025
1 parent 08f681c commit 05df996
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/actors/stubutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,18 @@ export const createRPCInvoker = <
const response = Promise.withResolvers<TResponse>();
const resolver: RequestResolver<TResponse> = { response };
pendingRequests.set(id, resolver);
const cleanup = () => {
const cleanup = (isErrored = false) => {
if (!pendingRequests.has(id)) {
return;
}
const channelClosed = new Error("Channel closed");
response.reject(channelClosed);
isErrored && resolver?.throw?.(channelClosed);
resolver.stream?.close();
resolver.ch?.close();
};
channel.closed.finally(cleanup);
channel.disconnected?.finally(cleanup);
channel.disconnected?.finally(() => cleanup(true));

try {
await channel.send({
Expand Down

0 comments on commit 05df996

Please sign in to comment.