mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
Delay Client error event
Right now the caller won't receive the event, because it's triggered before the function returns.
This commit is contained in:
parent
2f70256037
commit
0261bc11e7
1 changed files with 4 additions and 2 deletions
|
@ -36,8 +36,10 @@ export default class Client extends EventTarget {
|
|||
try {
|
||||
this.ws = new WebSocket(params.url);
|
||||
} catch (err) {
|
||||
this.dispatchEvent(new CustomEvent("error", { detail: "Failed to create connection: " + err }));
|
||||
setTimeout(() => this.dispatchEvent(new CustomEvent("close")), 0);
|
||||
setTimeout(() => {
|
||||
this.dispatchEvent(new CustomEvent("error", { detail: "Failed to create connection: " + err }));
|
||||
this.dispatchEvent(new CustomEvent("close"));
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
this.ws.addEventListener("open", this.handleOpen.bind(this));
|
||||
|
|
Loading…
Reference in a new issue