diff --git a/modules/calendar.js b/modules/calendar.js index a3ac2d1af5cd55a1997ad7b926434ed74155d0d1..6dbdfca505bec99a46ccd6ad5f3fb916d3b43fc5 100644 --- a/modules/calendar.js +++ b/modules/calendar.js @@ -100,16 +100,23 @@ function getData(count, cb) { } module.exports = function (io) { - io.on('connect', function (sock) { - sock.emit('calendar', Mustache.render(TEMPLATE, CALENDAR)); - }); - function update() { + function update(firstRunCallback) { getData(8, function (data) { CALENDAR = data; io.emit('calendar', Mustache.render(TEMPLATE, CALENDAR)); + if (firstRunCallback) { + firstRunCallback() + firstRunCallback = null; + } }); } - update(); + update(function () { + var pushToClients = function (sock) { + sock.emit('calendar', Mustache.render(TEMPLATE, CALENDAR)); + }); + io.on('connect', pushToClients); + pushToClients(io); + }); setInterval(update, 600000); }