@arashi/sockets
Advanced tools
Comparing version 0.0.0-dev.8 to 0.0.0-dev.9
@@ -94,7 +94,10 @@ "use strict"; | ||
return new Promise((resolve, reject) => { | ||
this._socket.once('error', (error) => { | ||
let connectCallback = null; | ||
let errCallback = (error) => { | ||
this._socket.removeListener('connect', connectCallback); | ||
reject(error); | ||
}); | ||
this._socket.once('connect', async () => { | ||
}; | ||
connectCallback = async () => { | ||
this._connected = true; | ||
this._socket.removeListener('error', errCallback); | ||
if (this._app.isClient()) { | ||
@@ -104,3 +107,5 @@ await this._app.getPacketFactory().createConnectionRequestPacket().send(this); | ||
resolve(); | ||
}); | ||
}; | ||
this._socket.once('error', errCallback); | ||
this._socket.once('connect', connectCallback); | ||
this._socket.connect(port, host); | ||
@@ -126,6 +131,8 @@ }); | ||
if (this.isConnected()) { | ||
this._socket.once('error', (err) => { | ||
let errCallback = (err) => { | ||
reject(err); | ||
}); | ||
}; | ||
this._socket.once('error', errCallback); | ||
this._socket.write(packet.serialize(), () => { | ||
this._socket.removeListener('error', errCallback); | ||
if (packet.isResponseRequired() && !this._contexts[packet.getID()]) { | ||
@@ -132,0 +139,0 @@ this._createContext(packet, new PromiseWrapper_1.PromiseWrapper(resolve, reject)); |
{ | ||
"name": "@arashi/sockets", | ||
"version": "0.0.0-dev.8", | ||
"version": "0.0.0-dev.9", | ||
"description": "Networking Library", | ||
@@ -5,0 +5,0 @@ "main": "lib/api.js", |
@@ -143,8 +143,11 @@ | ||
return new Promise<void>((resolve, reject) => { | ||
this._socket.once('error', (error: Error) => { | ||
let connectCallback: (() => void) = null; | ||
let errCallback = (error: Error) => { // Needs to reference connectCallback | ||
this._socket.removeListener('connect', connectCallback); | ||
reject(error); | ||
}); | ||
this._socket.once('connect', async () => { | ||
} | ||
connectCallback = async () => { // Needs to reference errCallback | ||
this._connected = true; | ||
this._socket.removeListener('error', errCallback); | ||
if (this._app.isClient()) { | ||
@@ -155,3 +158,5 @@ await this._app.getPacketFactory().createConnectionRequestPacket().send(this); | ||
resolve(); | ||
}); | ||
} | ||
this._socket.once('error', errCallback); | ||
this._socket.once('connect', connectCallback); | ||
this._socket.connect(port, host); | ||
@@ -183,6 +188,8 @@ }); | ||
// Writable.write error callback is unreliable and may or may not notify of errors. | ||
this._socket.once('error', (err: Error) => { | ||
let errCallback = (err: Error) => { | ||
reject(err); | ||
}); | ||
} | ||
this._socket.once('error', errCallback); | ||
this._socket.write(packet.serialize(), () => { | ||
this._socket.removeListener('error', errCallback); | ||
if (packet.isResponseRequired() && !this._contexts[packet.getID()]) { | ||
@@ -189,0 +196,0 @@ this._createContext(packet, new PromiseWrapper<TPacketResponse>(resolve, reject)); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115610
1609