An array which grows never completed a forEach #158

wants to merge 1 commit into


None yet

3 participants

rektide commented Aug 1, 2012

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.

rektide commented Aug 1, 2012

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.

@caolan caolan closed this Mar 2, 2013
rektide commented Oct 20, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment