Normal for loops can end early by using break
or return
. Might be useful to have the ability here too. Does that make sense?
Possible implementations:
Add a method for ending the iteration in the second argument to mapper
: mapper(index, stop)
:
pTimes(5, (i, stop) => {
if (shouldStop(i)) {
stop();
return;
}
return `foo ${i}`;
}).then();
Add ability to throw a special error to end the iteration without rejection the promise:
pTimes(5, i => {
if (shouldStop(i)) {
throw new pTimes.StopError();
}
return `foo ${i}`;
}).then();
Add ability to return special Symbol
to end the iteration:
pTimes(5, i => {
if (shouldStop(i)) {
return pTimes.StopSymbol;
}
return `foo ${i}`;
}).then();
While 2 and 3 are more verbose, they have the benefit of working even in a nested promise chain.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too