secret
Created

  • Download Gist
howitis.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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 ?');
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.