Skip to content

awesomeorganization/promise-queue

Repository files navigation

promise-queue

💥 [ESM] The promise-based queue with concurrency control. Works with Browser and Node.js


GitHub Workflow Codacy CodeFactor Snyk Depfu npms.io


Install

npm install @awesomeorganization/promise-queue

Example

Full example in /example folder.

const { push } = promiseQueue({
  concurrency: 2,
})
const [
  {
    headers: { date: dateA },
  },
  {
    headers: { date: dateB },
  },
  {
    headers: { date: dateC },
  },
] = await Promise.all([
  push(() => {
    return request('https://httpbin.org/delay/1')
  }),
  push(() => {
    return request('https://httpbin.org/delay/1')
  }),
  push(() => {
    return request('https://httpbin.org/delay/1')
  }),
])
console.dir({
  dateA,
  dateB,
  dateC,
})
// {
//   dateA: 'Wed, 26 Jan 2022 20:00:01 GMT',
//   dateB: 'Wed, 26 Jan 2022 20:00:02 GMT',
//   dateC: 'Wed, 26 Jan 2022 20:00:02 GMT',
// }