⚡ improve memory managment

This commit is contained in:
Flam3rboy
2021-10-12 21:53:57 +02:00
parent 270ad5ee38
commit b0385e0fcb
4 changed files with 13 additions and 4 deletions
+6 -3
View File
@@ -1,10 +1,13 @@
import { WebSocket } from "@fosscord/gateway";
import { Message } from "./Message";
import { Session } from "@fosscord/util";
export async function Close(this: WebSocket, code: number, reason: string) {
console.log("[WebSocket] closed", code, reason);
if (this.session_id) await Session.delete({ session_id: this.session_id });
// @ts-ignore
this.off("message", Message);
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
if (this.readyTimeout) clearTimeout(this.readyTimeout);
this.deflate?.close();
this.removeAllListeners();
}
+3
View File
@@ -18,6 +18,9 @@ export async function Send(socket: WebSocket, data: Payload) {
}
return new Promise((res, rej) => {
if (socket.readyState !== 1) {
return rej("socket not open");
}
socket.send(buffer, (err: any) => {
if (err) return rej(err);
return res(null);