Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var results = {}; // Stores results of async calculations
var render = function() { /* ... render the page using 'results' ... */};
var getDatabaseRecords = function(callback) { /* ... async stuff, storing results in 'results' ... */ };
var prepareAssetPaths = function(callback) { /* ... async stuff, storing results in 'results' ... */ };
var tasks = [getDatabaseRecords, prepareAssetPaths],
params = [
[],
[['stylesheet.scss', 'image.png', 'script.js']]
],
times = tasks.length;
tasks.forEach(function(task, index) {
var _params = params[index] || [];
_params.push(function() { if(--times === 0) render(); });
task.apply(this, _params);
});
@joesavage

This comment has been minimized.

Copy link
Owner Author

joesavage commented Jun 21, 2014

The async node module makes this kind of behaviour much easier to get at using async.parallel, plus provides a bunch of other useful stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.