Skip to content
Snippets Groups Projects
Commit 8ded7d0d authored by Kasalehlia's avatar Kasalehlia
Browse files

hardened weather module

parent aeb2a060
No related branches found
No related tags found
No related merge requests found
......@@ -64,22 +64,29 @@ function degToDirection(deg) {
return dir;
}
//fetchCurrent(CITYID, console.log);
//fetchForecast(CITYID, 3, console.log);
module.exports = function (io) {
var context = {};
var update = function () {
var update = function (firstUpdateCb) {
var then = function () {
if (context.current && context.forecast) {
firstUpdateCb();
}
};
fetchCurrent(CITYID, function (current) {
context.current = current;
then();
});
fetchForecast(CITYID, 6, function (forecast) {
context.forecast = forecast;
then();
});
};
update();
setInterval(update, 10*60*1000);
io.on('connect', function (sock) {
sock.emit('weather', Mustache.render(TEMPLATE, context));
update(function () {
var pushToClients = function (sock) {
sock.emit('weather', Mustache.render(TEMPLATE, context));
};
io.on('connect', pushToClients);
pushToClients(io);
});
setInterval(update, 10*60*1000);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment