1.2.1 • Published 2 years ago

@awesomeorganization/promise-queue v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

promise-queue

:boom: 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',
// }