Created
May 28, 2012 22:55
-
-
Save aroman/2821547 to your computer and use it in GitHub Desktop.
Yo Dawg we heard you liked async
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 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