Skip to content

Instantly share code, notes, and snippets.

@dscape
Created February 17, 2012 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscape/00663e475092e55ac66c to your computer and use it in GitHub Desktop.
Save dscape/00663e475092e55ac66c to your computer and use it in GitHub Desktop.
var insertElement = function(data, callback) {
var timeout = Math.ceil(Math.random() * 3000);
//console.log('timeout: ' + timeout.toString());
setTimeout(function() {
callback(null, data);
}, timeout);
};
var insertAll = function(coll, callback) {
// duplicate the array
var queue = coll.slice(0),
elem;
(function iterate() {
if(queue.length === 0) {
callback();
return;
}
elem = queue.splice(0, 1)[0];
})();
};
var coll = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
insertAll(coll, function() {
console.log('END ?');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment