Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Commit

Permalink
Change code for checkForAllServers function
Browse files Browse the repository at this point in the history
  • Loading branch information
izy521 committed Jan 6, 2017
1 parent 75145a5 commit 523f906
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,14 @@ function getOfflineUsers(client, servArr, callback) {
setTimeout( getOfflineUsers, 0, client, servArr, callback );
}

function checkForAllServers(client, ready, message) {
var all = Object.keys(client.servers).every(function(s) {
return !client.servers[s].unavailable;
});
if (all || ready[0]) return client.emit('ready', message);
setTimeout(checkForAllServers, 0, client, ready, message);
}

/* - Functions - Websocket Handling - */
function handleWSOpen(opts) {
var ident = {
Expand Down Expand Up @@ -1699,25 +1707,9 @@ function handleWSMessage(opts, data, flags) {
});

return (function() {
var ready = false;
var t = setTimeout(function() {
ready = true;
client.emit('ready', message);
}, 3500);
checkForAllServers();

function checkForAllServers() {
if (ready) return;
if (
Object.keys(client.servers).every(function(s) {
return !client.servers[s].unavailable;
})
) {
clearTimeout(t);
return client.emit('ready', message);
}
setTimeout(checkForAllServers, 0);
}
var ready = [false];
setTimeout(function() { ready[0] = true; }, 3500);
checkForAllServers(client, ready, message);
})();
case "MESSAGE_CREATE":
client.emit('message', _data.author.username, _data.author.id, _data.channel_id, _data.content, message);
Expand Down Expand Up @@ -2692,12 +2684,12 @@ function Websocket(url, opts) {
API: API,

ME: ME,
NOTE: function(userID) {
NOTE: function(userID) {
return ME + "/notes/" + userID;
},
LOGIN: API + "/auth/login",
LOGIN: API + "/auth/login",
OAUTH: API + "/oauth2/applications/@me",
GATEWAY: API + "/gateway",
GATEWAY: API + "/gateway",
SETTINGS: ME + "/settings",

SERVERS: function(serverID) {
Expand Down

0 comments on commit 523f906

Please sign in to comment.