async each for an array
/** | |
* for each item in the array, call a function, but only after the previous has called the callback. | |
**/ | |
function consecutive (list, task) { | |
var count = 0; | |
function step() { | |
var item = list[count]; | |
//console.log(count++); | |
if(typeof item === 'undefined') { | |
// console.log('this istem is undefined'); | |
return; | |
} | |
response = task(item, step); | |
} | |
step(); | |
} | |
/** | |
* usage | |
**/ | |
consecutive([5,8,4,6,5,7], function(item, cb){ | |
$.get( "ajax/test.php?amount="+item, function( data ) { | |
console.log( "Load was performed.", data ); | |
cb(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment