Skip to content

Instantly share code, notes, and snippets.

@TobyEalden
Created February 20, 2017 13:53
Show Gist options
  • Save TobyEalden/f3c3c20036753b537a601ad907e7ee6e to your computer and use it in GitHub Desktop.
Save TobyEalden/f3c3c20036753b537a601ad907e7ee6e to your computer and use it in GitHub Desktop.
let total = 0;
const processChunk = function(chunkList, chunkIndex) {
const chunk = chunkList[chunkIndex];
// do stuff with chunk asynchronously
return doStuff(chunk)
.then((result) => {
if (chunkIndex < chunkList.length) {
total += result;
// Process the next chunk.
return processChunk(chunkList, chunkIndex+1);
} else {
// Done
return totalResult;
}
});
};
const chunks = getArrayOfStuffToProcess();
const serialised = processChunk(chunks, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment