streamNotifications: publicProcedure.subscription(async function* (opts) {
try {
console.log(
"Listeners before setup:",
notificationEventEmitter.listenerCount("add"),
);
const iterable = on(notificationEventEmitter, "add");
console.log(
"Listeners after setup:",
notificationEventEmitter.listenerCount("add"),
);
opts.signal?.addEventListener("abort", () => {
console.log("Subscription aborted");
});
for await (const [notification] of iterable) {
yield notification as TNotification;
}
} catch (error) {
console.error("Error in notification stream:", error);
throw error; // Rethrow or handle as appropriate
} finally {
console.log("Stream closed");
}
}),
streamNotifications: publicProcedure.subscription(async function* (opts) {
try {
console.log(
"Listeners before setup:",
notificationEventEmitter.listenerCount("add"),
);
const iterable = on(notificationEventEmitter, "add");
console.log(
"Listeners after setup:",
notificationEventEmitter.listenerCount("add"),
);
opts.signal?.addEventListener("abort", () => {
console.log("Subscription aborted");
});
for await (const [notification] of iterable) {
yield notification as TNotification;
}
} catch (error) {
console.error("Error in notification stream:", error);
throw error; // Rethrow or handle as appropriate
} finally {
console.log("Stream closed");
}
}),