From 8ce05aa88ef77289b7a056015890d81e9ae4701b Mon Sep 17 00:00:00 2001 From: LobeliaComputing <31212444+ibuninngu@users.noreply.github.com> Date: Sat, 17 Feb 2024 19:57:00 +0900 Subject: [PATCH] _ --- src/js/websocket.awaitable.js | 18 ++++++++---------- src/tab/js/server.js | 3 +-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/js/websocket.awaitable.js b/src/js/websocket.awaitable.js index 2ba1947..3e7c968 100644 --- a/src/js/websocket.awaitable.js +++ b/src/js/websocket.awaitable.js @@ -11,18 +11,15 @@ export class AwaitbleWebSocket { this.socket.addEventListener("close", this.onClose); this.socket.addEventListener("error", this.onError); this.socket.messagePool = {}; - } - async waitOpen() { - let _this = this; - let R = new Promise((resolve, reject) => { - setInterval(() => { - if (_this.socket.isOpen) { - resolve(); + return new Promise((resolve, reject) => { + let interval_id = setInterval(() => { + if (this.socket.isOpen) { + resolve(this); + clearInterval(interval_id); } }, 10); }); - return R; } async send(message) { @@ -51,11 +48,12 @@ export class AwaitbleWebSocket { } } onClose(event) { - log(event); + // this -> this.socket this.isOpen = false; } onError(event) { - log(event); + // this -> this.socket + this.isOpen = false; } } \ No newline at end of file diff --git a/src/tab/js/server.js b/src/tab/js/server.js index 5ed55a0..494c9c0 100644 --- a/src/tab/js/server.js +++ b/src/tab/js/server.js @@ -186,8 +186,7 @@ window.BlueFoxScript = BlueFoxScript; let start_ws = async () => { - let webSocket = new AwaitbleWebSocket("ws://127.0.0.1:8888"); - await webSocket.waitOpen(); + let webSocket = await (new AwaitbleWebSocket("ws://127.0.0.1:8888")); let webSocketMessageHandler = { "getFileTree": async (data) => {