Last active
December 10, 2015 18:09
-
-
Save elbuo8/4472992 to your computer and use it in GitHub Desktop.
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 async = require('async'); //Dat speed | |
exports.loadAudioDefault = function(req, res) | |
{ | |
//This route returns a json object with an array of all the MongoDB documents | |
//returned by the query. These documents are audio files. | |
this.db.collection('audio', function(err, collection) | |
{ | |
var audio = { | |
'audio':[], | |
'settings':{ | |
'stations':[], | |
'hours':[] | |
}, | |
}; | |
var tasks = { | |
one:function(callback) | |
{ | |
console.log('First task'); | |
collection.find().toArray(function(err, docs) | |
{ | |
if (!err) | |
{ | |
audio.audio = docs; | |
console.log(audio); | |
callback(null, docs); | |
} | |
}); | |
}, | |
two: function(callback) | |
{ | |
console.log('Second task'); | |
collection.distinct('station', function(err, docs) | |
{ | |
if (!err) | |
{ | |
audio.settings.stations.push(docs); | |
console.log(audio.settings.stations); | |
callback(null, docs); | |
} | |
}); | |
}, | |
three: function(callback) | |
{ | |
console.log('Third task'); | |
collection.distinct('hour', function(err, docs) | |
{ | |
if (!err) | |
{ | |
audio.settings.hours.push(docs); | |
console.log(audio.settings.hours); | |
callback(null, docs); | |
} | |
}); | |
} | |
}; | |
async.parallel(tasks, function(err, results) | |
{ | |
console.log('Mother callback. Data:', audio); | |
console.log(results); | |
res.render('audioBody', audio); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment