sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.48k stars 185 forks source link

Allow not to copy/paste throwOnTimeout #214

Open IlyaSemenov opened 4 days ago

IlyaSemenov commented 4 days ago

Currently, user must always copy/paste { throwOnTimeout: true } in each and every .add() call otherwise they end up with void in their typings:

import Queue from "p-queue"

const queue = new Queue({
  concurrency: 1,
  interval: 1500,
  intervalCap: 1,
  throwOnTimeout: true, // regardless of this
})

// typed as number | void 
const value1 = await queue.add(async () => 123)

// typed as number
const value2 = await queue.add(async () => 123, { throwOnTimeout: true })

Can we please have some way to reduce this boilerplate? Either extend class typings to lookup the init options, or add a shortcut method such as queue.execute (?) which will do { throwOnTimeout: true } on its own.