Skip to content

Instantly share code, notes, and snippets.

@ncb000gt
Created February 16, 2011 15:50
Show Gist options
  • Save ncb000gt/829593 to your computer and use it in GitHub Desktop.
Save ncb000gt/829593 to your computer and use it in GitHub Desktop.
Async dep example with Cradle.
var data = [1,2,3,4,5,6,7,8,9,10],
len = data.length,
count = 0;
function f() {
//do your dependent stuff here
}
data.forEach(function(i) {
db.save(key, {val: i}, function(err, res) {
//data for i saved yay!
count++;
if (count === len) {
f();
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment