Skip to content

Instantly share code, notes, and snippets.

@xsurge83
Last active August 29, 2015 14:01
Show Gist options
  • Save xsurge83/bf35b6ea76625bc0c7fa to your computer and use it in GitHub Desktop.
Save xsurge83/bf35b6ea76625bc0c7fa to your computer and use it in GitHub Desktop.
Aggregate in Sync order
var ids = [1,2,3];
var aggregateIds = function(ids, obj, callback){
var id;
if(!obj){
obj = {};
}
if(ids.length){
setTimeout(function(){
var id = ids.shift();
obj[id] = id;
aggregateIds(ids, obj, callback);
}, 500);
} else {
return callback(null, obj);
}
}
aggregateIds([1,3,4], null, function(error, result){
console.log("%j", result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment