Explorar o código

feat: add dispatchAsync wrapper for socket dispatch function, using promises instead of callbacks

Kristian Vos hai 1 día
pai
achega
a239743c0c
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  1. 11 0
      frontend/src/classes/SocketHandler.class.ts

+ 11 - 0
frontend/src/classes/SocketHandler.class.ts

@@ -189,6 +189,17 @@ export default class SocketHandler {
 		return this.socket.send(JSON.stringify([...args]));
 	}
 
+	dispatchAsync(...args: [string, ...any]) {
+		return new Promise(resolve => {
+			this.dispatch(...args, (res, ...extraRes) => {
+				resolve({
+					res,
+					extraRes
+				});
+			});
+		});
+	}
+
 	onConnect(cb: (...args: any[]) => any, persist = false) {
 		if (this.socket && this.socket.readyState === 1 && this.ready) cb();