From f0343d2dbef6a2a3e4d23f688e5a007830c54414 Mon Sep 17 00:00:00 2001 From: Schmoopiie Date: Wed, 24 May 2017 10:29:54 -0400 Subject: [PATCH] client: should fix the UnhandledPromiseRejectionWarning #201 #225 #227 #229 --- lib/client.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index 8abe5f55..074545f4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1037,9 +1037,10 @@ client.prototype._getPromiseDelay = function _getPromiseDelay() { // Send command to server or channel.. client.prototype._sendCommand = function _sendCommand(delay, channel, command, fn) { // Race promise against delay.. - return new Promise((resolve, reject) => { - _.promiseDelay(delay).then(() => { reject("No response from Twitch."); }); - + var timeout = new Promise((resolve, reject) => { + _.promiseDelay(delay).then(() => { reject("No response from Twitch."); }) + }); + var promise = new Promise((resolve, reject) => { // Make sure the socket is opened.. if (!_.isNull(this.ws) && this.ws.readyState !== 2 && this.ws.readyState !== 3) { // Executing a command on a channel.. @@ -1055,11 +1056,12 @@ client.prototype._sendCommand = function _sendCommand(delay, channel, command, f } fn(resolve, reject); } - // Disconnected from server.. else { reject("Not connected to server."); } }); -}; + + return Promise.race([timeout, promise]); +} // Send a message to channel.. client.prototype._sendMessage = function _sendMessage(delay, channel, message, fn) {