Hi @MatthewWid ! I came across your library and was trying it out with Sveltekit. The setup is straightforward:
export const GET: RequestHandler = async ({ request }) => {
return createResponse(request, (session) => {
session.push('Hello world');
});
};
This works, however, the session never seems to be disconnected properly. For instance, setting up a ticker like this:
export const GET: RequestHandler = async ({ request }) => {
return createResponse(request, (session) => {
const tick = setInterval(() => {
session.push(`The time is: ${new Date()}`);
}, 1000);
session.on("disconnected", () => {
clearInterval(tick);
});
});
};
When the client disconnects (e.g.: navigating , or refreshing page), the Session is still active and will try to still send the message. The server will crash with:
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
Minimum repo: better-sse-sveltekit
Hi @MatthewWid ! I came across your library and was trying it out with Sveltekit. The setup is straightforward:
This works, however, the session never seems to be disconnected properly. For instance, setting up a ticker like this:
When the client disconnects (e.g.: navigating , or refreshing page), the
Sessionis still active and will try to still send the message. The server will crash with:Minimum repo: better-sse-sveltekit