Skip to content

Instantly share code, notes, and snippets.

@deedubs
Created February 29, 2012 22:10
Show Gist options
  • Save deedubs/1944854 to your computer and use it in GitHub Desktop.
Save deedubs/1944854 to your computer and use it in GitHub Desktop.
callbacking
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