Created
February 29, 2012 22:10
-
-
Save deedubs/1944854 to your computer and use it in GitHub Desktop.
callbacking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stats; | |
app.get('/questions', auth.requireUser, function(req, res) { | |
var status = req.query.status || 'Asked'; | |
Question | |
.where('status', status) | |
.find(function(err, questions) { | |
res.locals({ | |
questions: questions | |
, currentStatus: status | |
, stats: stats | |
}); | |
res.render('questions'); | |
}); | |
}); | |
function updateStats() { | |
Question.count({ status : 'Asked' }, function(err, askedCount){ | |
Question.count({ status : 'AlreadyAnswered' }, function(err, answeredCount){ | |
Question.count({ status : 'NeedAnswer' }, function(err, needsAnswerCount){ | |
Question.count({ status : 'Complete' }, function(err, completeCount){ | |
stats = { | |
asked: askedCount | |
, answered: answeredCount | |
, needsAnswer: needsAnswerCount | |
, complete: completeCount | |
}; | |
}); | |
}); | |
}); | |
}); | |
} | |
updateStats(); | |
setInterval(updateStats, 10000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment