Created
February 2, 2012 22:25
-
-
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
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') | |
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