From 5012cd7771d3af1bd6d1175b391c96445f71b739 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Tue, 24 Nov 2015 17:24:17 -0600 Subject: [PATCH] Fix horribly broken code --- app.js | 16 +++++----------- lib/util.js | 8 ++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 9c1ddc3..07d1cc3 100644 --- a/app.js +++ b/app.js @@ -33,10 +33,10 @@ function pingAll() { } }; - if (networkSnapshot) { - object.result = res; + if (res) { + networkSnapshot.result = res; } else if (err) { - networkSnapshot.err = error; + networkSnapshot.error = err; } server.io.sockets.emit('update', networkSnapshot); @@ -80,19 +80,13 @@ function pingAll() { // Start our main loop that does everything. function startMainLoop() { - setInterval(pingAll, config.rates.pingAll); + util.setIntervalNoDelay(pingAll, config.rates.pingAll); - setInterval(function() { + util.setIntervalNoDelay(function() { mojang.update(config.rates.mojangStatusTimeout); server.io.sockets.emit('updateMojangServices', mojang.toMessage()); }, config.rates.upateMojangStatus); - - // Manually fire the first round of our tasks. - mojang.update(config.rates.mojangStatusTimeout); - server.io.sockets.emit('updateMojangServices', mojang.toMessage()); - - pingAll(); } server.start(function() { diff --git a/lib/util.js b/lib/util.js index 667854d..c8aa50a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,3 +1,11 @@ exports.getCurrentTimeMs = function() { return new Date().getTime(); +}; + +exports.setIntervalNoDelay = function(func, delay) { + var task = setInterval(func, delay); + + func(); + + return task; }; \ No newline at end of file