Skip to content

Instantly share code, notes, and snippets.

@brynbellomy
Created February 2, 2012 22:25
Show Gist options
  • Save brynbellomy/1726178 to your computer and use it in GitHub Desktop.
Save brynbellomy/1726178 to your computer and use it in GitHub Desktop.
example of using async library to fetch 3 datasets, the third being dependent on the first two
var async = require('async')
async.parallel(
{
// one way of doing it
getPeople: harvest.getPeople,
// another way of doing it
getProjects: function(parallelCallback) {
harvest.getProjects(parallelCallback)
},
// a third way of doing it
getCake: function(parallelCallback) {
harvest.getCake(function(msg, data) {
parallelCallback(null, {msg: msg, data: data})
})
}
},
function(err, results) {
if (err) {
// ...
}
getHoursUsing(results.getPeople, results.getProjects, doneGettingHours)
}
)
function doneGettingHours(err, allHours) {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment