Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should fix the UnhandledPromiseRejectionWarning #201 #225 #227 #229 #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand All @@ -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) {
Expand Down