From 152b136ab4cbe7b3a0223cd9a0be96b71f100e79 Mon Sep 17 00:00:00 2001 From: Kasalehlia <kasalehlia@clonejo.de> Date: Tue, 17 Nov 2015 20:22:54 +0100 Subject: [PATCH] hardened calendar module --- modules/calendar.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/calendar.js b/modules/calendar.js index a3ac2d1..6dbdfca 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); } -- GitLab