Patch and implementation to allow async.forEach to complete even if the array grows in size.
There is an alternative implementation rektide@3eda642 that avoids this somewhat-hackish recursion (and the cost of building & storing additional state): it does, however, not make use of _forEach, & I was not sure what costs are associated with not using native Array.forEach when it is available.
Either that implementation, or this rektide@76db4af implementation, both resolve the issue, which is demonstrated in the test.
allow forEach to complete even if it's array grows.
Alternative implementation is flawed, does not work: the iterators have all been called, and there's nothing to compensate for the change in size. This first fix is the suggested one.
I think it is semantically incorrect to use forEach for a dynamic array. Queue should be used instead. This issue should be closed.
Please reconsider. Why impose a limited, constrained use over an equivalent one that will not pain any existing users yet which will enable alternative use cases? Queue has a very different usage pattern I'm not comfortable imposing on anyone wanting to use dynamic data. Please loosen up, and accept a wider range of inputs.
If nothing else, you should at least fix your code so that adding to an array throws or completes. You have an idea of semantically what you want to accept? Fine, enforce it.