fix: controller is already closed trpc subscription observable error (#743)

This commit is contained in:
Meier Lukas
2024-07-03 20:31:06 +02:00
committed by GitHub
parent f557fbbae1
commit 41dba7b516
6 changed files with 33 additions and 12 deletions

View File

@@ -9,10 +9,17 @@ import { createTRPCRouter, publicProcedure } from "../trpc";
export const logRouter = createTRPCRouter({
subscribe: publicProcedure.subscription(() => {
return observable<LoggerMessage>((emit) => {
let isConnectionClosed = false;
loggingChannel.subscribe((data) => {
if (isConnectionClosed) return;
emit.next(data);
});
logger.info("A tRPC client has connected to the logging procedure");
return () => {
isConnectionClosed = true;
};
});
}),
});