bug: wrong length of returned value when iterable is the same size as limit
Opened this issue · 0 comments
alrico88 commented
Hello,
I've encountered an issue with simultan when iterable and limit are the same size. The resolved promise has 1 less item than expected.
Here's a quick repro. You can check it here live if you'd like: https://runkit.com/alrico88/simultan-issue-repro
const {simultan} = require('simultan');
const {sleep, Unit} = require('espera');
const response = await simultan(['1', '2', '3'], async (d) => {
await sleep(1, Unit.seconds);
return d;
}, 3);
The expected response should be ['1', '2', '3'],
but instead it returns ["1", "2"]
.
I think the issue stems from using Promise.race
when iterable.length === limit
. Wouldn't it be better to directly apply Promise.all
in that case?