@awesomeorganization/promise-queue

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

Usage no npm install needed!

<script type="module">
  import awesomeorganizationPromiseQueue from 'https://cdn.skypack.dev/@awesomeorganization/promise-queue';
</script>

README

promise-queue

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


npm npm npm npm npm npm


Example

Full example in /example folder.

import { promiseQueue } from '@awesomeorganization/promise-queue'
import undici from 'undici'

const example = async () => {
  const { push } = promiseQueue({
    concurrency: 2,
  })
  const [
    {
      headers: { date: dateA },
    },
    {
      headers: { date: dateB },
    },
    {
      headers: { date: dateC },
    },
  ] = await Promise.all([
    push(() => {
      return undici.request('https://httpbin.org/delay/1')
    }),
    push(() => {
      return undici.request('https://httpbin.org/delay/1')
    }),
    push(() => {
      return undici.request('https://httpbin.org/delay/1')
    }),
  ])
  console.dir({
    dateA,
    dateB,
    dateC,
  })
}

example()