EDIT: I just realized that it fires only when effectively CANCELLED, meaning that the stream should not return before clearing resources or stay open forever, my bad :D
Hi, I'm trying to work with eventlisteners which I must close when the request is closed in any way
The onCancel callback doesn't seem to do anything
Even if I close the window/browser nothing happens
Is there any way to accomplish this ?
import { events } from 'sveltekit-sse'
export const GET = async (request) => {
const evts = events(async (emit) => {
let x = 0;
while (true) {
await new Promise((resolve) => setTimeout(resolve, 1000))
emit("message", 'message')
if (x++ === 2) break
}
}).onCancel(() => console.log("FIRE"))
return evts.toResponse()
}
I just realized that it fires only when effectively CANCELLED, meaning that the stream should not return before clearing resources or stay open forever, my bad :D
EDIT: I just realized that it fires only when effectively CANCELLED, meaning that the stream should not return before clearing resources or stay open forever, my bad :D
Hi, I'm trying to work with eventlisteners which I must close when the request is closed in any way
The onCancel callback doesn't seem to do anything Even if I close the window/browser nothing happens
Is there any way to accomplish this ?
I'm running on