There's a tradeoff here.
If it's an extension of `for...of`, it's much clearer for users. If it's
a method of `Promise`, it's much more extensible.
Perhaps it could be a little bit of both?
Maybe something like:
```
for(item of items : Scheduler.limit(5)) {
// ...
}
```
where `Scheduler.limit` is one of several possible execution strategies?
One could imagine more advanced strategies, such as sharing a scheduler
between several loops, or adapting scheduling to external constraints
such as memory pressure.
One possible semantics for this would be to treat it as syntactic sugar for:
```
Scheduler.limit(5)(function*() {
for(item of items) {
// ...
}
})
```
Cheers,
David
On 07/09/2019 20:27, Cyril Auburtin wrote:
> It should really be in the form of a static method like `Promise.map`
> or some other naming
>
> On Sat, Sep 7, 2019 at 6:40 PM Tom Boutell <[email protected]
> <mailto:[email protected]>> wrote:
>
> Up to five instances of the loop body would be in progress, assuming
> at least one of them awaits at some point. any await inside the loop
> body would be respected with regard to code that follows it in the
> loop body. The only place concurrency comes into play is that more
> than one of these loopbodies could be in progress for separate
> items, for instance they could all be awaiting a long database
> operation or API call. To avoid the frequent problems that come up
> with unlimited concurrency when dealing with apis and similar, you
> set the concurrency so that you don't exceed those reasonable limits.
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss