Created
February 20, 2017 13:53
-
-
Save TobyEalden/f3c3c20036753b537a601ad907e7ee6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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