Skip to content

Instantly share code, notes, and snippets.

@aroman
Created May 28, 2012 22:55
Show Gist options
  • Save aroman/2821547 to your computer and use it in GitHub Desktop.
Save aroman/2821547 to your computer and use it in GitHub Desktop.
Yo Dawg we heard you liked async
var interator_func = function(array_element, callback) {
wraps_waterfall('foo', function (err, top_level_data)
async.waterfall([
function(wf_callback) {
// do work
wf_callback(null, data);
},
function(data, wf_callback) {
// call an async function with work
an_async_function(data, function(results) {
wf_callback(results, data);
});
},
function(results, data, wf_callback) {
// more work
wf_callback(null, data);
// reference a top level variable
data.blah = top_level_data;
}
], function(err, data) {
// final work
callback();
});
});
};
async.forEach(an_array, interator_func, function(err) {
// interator_func has now been called on every
// element in an_array.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment