I'm using Node v8.10.0
The above question explains how Node.js doesn't support TCO anymore. I recently experienced an issue with a function like this though:
async function processBatch(nthBatch) {
// do a bunch of async work and build up variables
await processBatch(nthBatch + 1);
}
The code had a memory leak which was immediately fixed by changing this to:
async function processBatch(nthBatch) {
// do a bunch of async work and build up variables
return processBatch(nthBatch + 1);
}
I'm surprised that actually worked, because in the question described above, it clearly explains that TCOs aren't supported in Node 8.x. So is there something special going on that enables a TCO here? Or is it because it's using a generator under the hood and the return marks the generator as done, so the stack can be discarded?