Fixes T5042.
The Futures iterator currently only takes the first 8 items from the waiting list and uses that as the working set. Unfortunately items are only popped from the top of the waiting list as fast as they are processed in PHP, which means if the tasks are executing faster than PHP is processing the results, then the number of running tasks will be lower than the limit.
This fixes the issue by counting up to the limit when taking items from the waiting list, not counting items that are resolved (but still adding them to the working set so we can respond to them exiting). Thus it ensures that there are always limit unresolved futures active, with the a certain number of the working set already resolved and ready to be processed.