raszi / node-tmp

Temporary file and directory creator for node.js
MIT License
739 stars 93 forks source link

Should `_rmdirRecursiveSync` be re-implemented using a loop? #17

Closed michaelsbradleyjr closed 9 years ago

michaelsbradleyjr commented 11 years ago

See #840(bower).

When there are a large number of directories to clean up, the current implementation seems to result in a "Maximum call stack size exceeded" exception.

raszi commented 11 years ago

How do you want to achieve that without recursion? I could not imagine a solution without a recursion.

michaelsbradleyjr commented 11 years ago

It's possible to convert recursive functions into non-recursive loops, through a technique generally referred to as "trampolining":

http://raganwald.com/2013/03/28/trampolines-in-javascript.html

silkentrance commented 9 years ago

@michaelsbradleyjr Trampolines are way too complicated for this easy task, just use an array as a stack and fill this up with the directories that need to be cleaned, emptying the stack along the way and everything is fine...

Will provide a PR for this.