fix: controller is already closed trpc subscription observable error (#743)
This commit is contained in:
@@ -27,14 +27,19 @@ export const appRouter = createTRPCRouter({
|
||||
const pingResult = await sendPingRequestAsync(input.url);
|
||||
|
||||
return observable<{ url: string; statusCode: number } | { url: string; error: string }>((emit) => {
|
||||
let isConnectionClosed = false;
|
||||
|
||||
emit.next({ url: input.url, ...pingResult });
|
||||
pingChannel.subscribe((message) => {
|
||||
if (isConnectionClosed) return;
|
||||
|
||||
// Only emit if same url
|
||||
if (message.url !== input.url) return;
|
||||
emit.next(message);
|
||||
});
|
||||
|
||||
return () => {
|
||||
isConnectionClosed = true;
|
||||
void pingUrlChannel.removeAsync(input.url);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -25,15 +25,21 @@ export const mediaServerRouter = createTRPCRouter({
|
||||
.unstable_concat(createManyIntegrationMiddleware("jellyfin", "plex"))
|
||||
.subscription(({ ctx }) => {
|
||||
return observable<{ integrationId: string; data: StreamSession[] }>((emit) => {
|
||||
let isConnectionClosed = false;
|
||||
|
||||
for (const integration of ctx.integrations) {
|
||||
const channel = createItemAndIntegrationChannel<StreamSession[]>("mediaServer", integration.id);
|
||||
void channel.subscribeAsync((sessions) => {
|
||||
if (isConnectionClosed) return;
|
||||
emit.next({
|
||||
integrationId: integration.id,
|
||||
data: sessions,
|
||||
});
|
||||
});
|
||||
}
|
||||
return () => {
|
||||
isConnectionClosed = true;
|
||||
};
|
||||
});
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -13,12 +13,19 @@ export const smartHomeRouter = createTRPCRouter({
|
||||
entityId: string;
|
||||
state: string;
|
||||
}>((emit) => {
|
||||
let isConnectionClosed = false;
|
||||
|
||||
homeAssistantEntityState.subscribe((message) => {
|
||||
if (isConnectionClosed) return;
|
||||
if (message.entityId !== input.entityId) {
|
||||
return;
|
||||
}
|
||||
emit.next(message);
|
||||
});
|
||||
|
||||
return () => {
|
||||
isConnectionClosed = true;
|
||||
};
|
||||
});
|
||||
}),
|
||||
switchEntity: publicProcedure
|
||||
|
||||
Reference in New Issue
Block a user