Open david-plugge opened 1 year ago
Ok, I found out how to do it now: you need to take the raw Request
object from the context of the function (https://elysiajs.com/concept/handler.html#context) and add an eventListener
to it:
request.signal.addEventListener("abort", () => {
console.log("closed");
});
To be more precise, we could use a custom function like so:
function signalCb(this: AbortSignal, ev: Event) {
sub.unsubscribe(); // perform unsubscribe from subscribed things
stream.close();
this.removeEventListener("abort", signalCb); // yes, I am scared
}
request.signal.addEventListener("abort", signalCb, { once: true });
Blocked by https://github.com/elysiajs/stream/issues/10
When the client closes the connection, the server maybe has to do something like clearing an interval.
How am i supposed to achive that with the current version? I´d expect to be able to return a callback that will be called when the connection is closed to handle such stuff.