Skip to content

Instantly share code, notes, and snippets.

@Darkle
Created December 4, 2015 04:27
Show Gist options
  • Save Darkle/10d8045480ebfa33ded0 to your computer and use it in GitHub Desktop.
Save Darkle/10d8045480ebfa33ded0 to your computer and use it in GitHub Desktop.
function process(chunks, index) {
var chunk = chunks[index];
if (_.isUndefined(chunk)) {
return;
};
console.log('doing expensive work ' + _.last(chunk));
_.defer(_.partial(process, chunks, ++index));
}
var collection = _.range(10000),
chunks = _.chunk(collection, 50);
process(chunks, 0);
// →
// doing expensive work 49
// doing expensive work 99
// doing expensive work 149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment