sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.39k stars 182 forks source link

Fix timeout-dependent return types of `add` and `addAll` #206

Open lukehorvat opened 2 months ago

lukehorvat commented 2 months ago

Hi. The return types of add and addAll are currently a bit funky. I think there was a regression.

For example, the following code raises a type error for b because it thinks a is number | void:

const a = await this.queue.add(async () => 1);
const b: number = a * 2;

That doesn't seem right. It should only return number | void when both timeout=number and throwOnTimeout=false|undefined. But in the example above I haven't even specified timeout, so the void behavior should never surface.

This PR fixes the return types:

To further emphasize the relationship between timeout and throwOnTimeout I also added a note in the readme and a warning message in the console.