Asynchronous iterator for AngularJS
Regarding the desire to make an implementation of the $q service, it is useful to consider that angular's $q is a stripped down version of the excellent promise library q by, kriskowal which you can leverage independently of angular. You can also achieve it through other promise implementations such as bluebird and with native ES2015 promises where available.

As for the implementation itself, I strongly recommend removing the serialOrParallel and doing one of the following.


Turn you function into an object which exposes a parallel and a sequential property. Ex: 

var forEach = { 
    parallel: function () {...},
    sequential: function() {...}
} 

Create 2 separate functions, one that traverses sequentially and one that traverses in parallel.


The reasoning behind this is that it makes the code clearer, removes the need for an exception, and makes it easier for consumers to do the right thing.

As @Roamer-1888 noted, In the serial case, it should be possible to construct returnValues in its entirety in the forEach loop without post-processing it.